SWI-Prolog 文件需要开始和结束字符吗?
我是 SWI-Prolog 的新手,正在尝试一些教程。然而,我尝试通过命令行加载的每个文件都会收到 2 条错误消息 - 一条位于开头(操作员预期),一条位于末尾(意外的文件结尾)。文件保存在与我正在工作的目录相同的目录中。
例如,我将此文件保存为 kb2.pl
listensToMusic(mia).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
listensToMusic(yolanda):- happy(yolanda).
从打开 Prolog 开始(通过 /opt/local/bin/swipl),我的命令行看起来像这样:
% 库(swi_hooks) 编译成 pce_swi_hooks 0.00 秒,3,928 字节
欢迎使用 SWI-Prolog(多线程,64 位,版本 5.10.2)
版权所有 (c) 1990-2010 阿姆斯特丹大学,VU 阿姆斯特丹
SWI-Prolog 不附带任何保证。这是免费软件,
欢迎您在一定条件下重新分发它。
请访问 http://www.swi-prolog.org 了解详细信息。帮助,使用?-帮助(主题)。或 ?- apropos(Word)。
?- [kb2].
错误:/Users/name/Desktop/kb2.pl:1:0:语法错误:需要运算符
错误:/Users/name/Desktop/kb2.pl:10:52:语法错误:意外的文件结尾
% kb2 编译时间 0.00 秒,2,584 字节
正确。?-
当我要求列出已编译文件时,我得到:
\快乐(yolanda)。
\playsAirGuitar(mia) :- 听音乐(mia)。
\playsAirGuitar(yolanda) :- 听音乐(yolanda)。
真的。
所以它会删除文件的第一行和最后一行。
我在线搜索了这些错误消息,发现了很多有关 Prolog 格式的有用提示,但没有一个可以解决这种情况。 Prolog 文件的开头和结尾是否应该使用某种特殊字符或格式?
I'm new to SWI-Prolog and am trying some tutorials. Every file I try to load through the command line, however, gets 2 error messages - one at the start (Operator expected) and one at the end (Unexpected end of file). Files are saved in the same directory as the one I'm working in.
For example, I have this file saved as kb2.pl
listensToMusic(mia).
happy(yolanda).
playsAirGuitar(mia) :- listensToMusic(mia).
playsAirGuitar(yolanda) :- listensToMusic(yolanda).
listensToMusic(yolanda):- happy(yolanda).
From the start of opening Prolog (through /opt/local/bin/swipl), my command line looks like this:
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,928 bytes
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.2)
Copyright (c) 1990-2010 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.help, use ?- help(Topic). or ?- apropos(Word).
?- [kb2].
ERROR: /Users/name/Desktop/kb2.pl:1:0: Syntax error: Operator expected
ERROR: /Users/name/Desktop/kb2.pl:10:52: Syntax error: Unexpected end of file
% kb2 compiled 0.00 sec, 2,584 bytes
true.?-
When I ask for the listing of the compiled file, I get:
\happy(yolanda).
\playsAirGuitar(mia) :- listensToMusic(mia).
\playsAirGuitar(yolanda) :- listensToMusic(yolanda).
true.
So it's cutting out the first and last lines of the file.
I've searched for these error messages online and found a lot of useful hints about formatting for Prolog, but none that address this situation. Is there some sort of special character or formatting that should be used for the start and end of a file for Prolog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是哪个操作系统?您确定该文件是 ASCII(而不是 UTF-16)吗?它有适合您的平台的本地行结尾吗?您可以发布整个文件(原始)以便人们可以检查吗?
Which operating system are you on? Are you sure the file is ASCII (and not UTF-16)? Does it have the native line ending for your platform? Can you post the whole file (raw) so people can check it?
许多 Prolog 系统,例如 SWI-Prolog、Jekejeke Prolog,允许将 BOM 检测为文本文件的第一个字符。 BOM 是一些空格,表示文本文件的编码:
因此无需将自己限制为 ASCII。许多文本编辑器会为您放置 BOM。而SWI-Prolog、Jekejeke Prolog则默认探测BOM。
Many Prolog systems, such as SWI-Prolog, Jekejeke Prolog, allow to detect a BOM as the first character of a text file. The BOM is some white space, that indicates the encoding of the text file:
So there is no need to restrict yourself to ASCII. Many text editors will place the BOM for you. And SWI-Prolog, Jekejeke Prolog, by default probe the BOM.