且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

写入文件 |Swi-Prolog |视窗

更新时间:2022-06-27 01:05:29

如果想将 close(OS) 保留在单个"ma​​in/0 子句中,这也有效:>

If one wanted to keep the close(OS) within a "single" main/0 clause, this also works:

main :-
    open('output.txt',write,OS),
    (   elements(Points),
        get_set(Eq, Points),
        alpha_isotone(Eq, Points),
        write(OS,Eq),nl(OS),
        false
        ;
        close(OS)
    ).

不推荐使用这种语法,因为很难记住连词 , 与析取 ; 的优先级是什么,除非您经常使用这种编码,并且它是该帐户的可读性不如 larsmans 提供的版本.

This syntax is not recommended as it is hard to remember what is the precedence of the conjunction , versus disjunction ; unless you frequently use such coding, and it is on that account less readable than the version presented by larsmans.

Prolog 定义了运算符的相对优先级,即使对于 AND、OR 和颈部":-,通过为每个运算符分配 Precedence 值(用户使用 op/3 定义自己的运算符时),范围从 0 到 1200.

Prolog defines the relative precedence of operators, even for AND, OR, and "neck" :-, by assigning Precedence values to each (users do this with op/3 when defining their own operators), ranging from 0 to 1200.

这里也有一个与通常的约定相反的情况,我们通常指的是较高优先级运算符应在较低优先级运算符之前应用.但是在 Prolog 中 较低的优先级 value 表示运算符首先绑定(应用).

There is also a reversal of the usual convention here, in that we normally mean the higher precedence operator is to be applied before lower precedence operators. But in Prolog the lower Precedence value indicates an operator binds (is applied) first.

实际优先级值因实现而异,但连词 ,Precedence 值低于析取符 ;,因此先绑定.

Actual precedence values vary with the implementation, but conjunction , has lower Precedence value than disjunction ; and thus binds first.