如何从命令行运行SWI-Prolog?

 热情article文章_673_621 发布于 2022-12-25 23:20

有没有办法只创建一个这样的prolog脚本hello.pl:

#!/usr/local/bin/swipl -q -s -t main

main:-
  write('Hello World\n').

能够像这样从终端运行吗?

$ hello.pl
Hello World
$

当我这样做时它给了我这个:

hello.pl: line 3: main:-: command not found
hello.pl: line 4: syntax error near unexpected token `'Hello World\n''
hello.pl: line 4: `  write('Hello World\n').'

我可以通过在命令行上写这个来使它工作:

$ swipl -q -f hello.pl -t main
Hello World
$

但有没有办法将直接脚本作为可执行文件运行?

编辑

还没有能够让这个工作.以下是@Boris在其答案评论中提出的命令的输出:

$ ls -l
total 8
-rwxr-xr-x  1 viatropos  staff  235 Aug 26 20:28 example.pl
$ cat example.pl
#!/usr/local/bin/swipl

:- set_prolog_flag(verbose, silent).

:- initialization main.

main :-
    format('Example script~n'),
    current_prolog_flag(argv, Argv),
    format('Called with ~q~n', [Argv]),
    halt.
main :-
    halt(1).
$ which swipl
/usr/local/bin/swipl
$ swipl --version
SWI-Prolog version 6.6.6 for x86_64-darwin13.1.0
$ ./example.pl
./example.pl: line 3: syntax error near unexpected token `('
./example.pl: line 3: `:- set_prolog_flag(verbose, silent).'
$

我在Mac OSX 10.9.2上,并安装swipl与homebrew via brew install swi-prolog --with-libarchive

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有