写入文件 |Swi-Prolog |视窗 [英] Writing in file | Swi-Prolog | Windows

查看:41
本文介绍了写入文件 |Swi-Prolog |视窗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些脚本在 swi-prolog 5.11.11 linux 系统上运行成功,但在 windows 系统上运行不太好,Swi-Prolog 5.6.48

Some script is working successful by swi-prolog 5.11.11 on linux-system, but not so well on windows-system by Swi-Prolog 5.6.48

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

问题 - windows 下的文件 output.txt 为空,所有信息都停留在伪终端中.在 linux 下它运行良好,但经常丢失文件结尾.喜欢

Problem - under the windows file output.txt is empty and all information is staying in pseudo-terminal. Under linux it's working well, but end of file is missed often. Like

>> tail output.txt      
[6,1,3,6,6,6]
[6,1,6,6,6,6]
[6,3,1,6,6,6]
[6,3,3,6,3,6]
[6,3,3,6,5,6]
[6,3,3,6,6,6]
[6,3,6,6,6,6]
[6,6,1,6,6,6]
[6,6,3,6,6,6]
[6,6,6,

我做错了什么?(除了我的英语)

What am I doing wrong? (except of my english)

推荐答案

如果想将 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.

这篇关于写入文件 |Swi-Prolog |视窗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆