有没有办法只创建一个这样的prolog脚本hello.pl:
#!/usr/local/bin/swipl -q -s -t main
main:-
write('Hello World\n').
Run Code Online (Sandbox Code Playgroud)
能够像这样从终端运行吗?
$ hello.pl
Hello World
$
Run Code Online (Sandbox Code Playgroud)
当我这样做时它给了我这个:
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').'
Run Code Online (Sandbox Code Playgroud)
我可以通过在命令行上写这个来使它工作:
$ swipl -q -f hello.pl -t main
Hello World
$
Run Code Online (Sandbox Code Playgroud)
但有没有办法将直接脚本作为可执行文件运行?
编辑
还没有能够让这个工作.以下是@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 …Run Code Online (Sandbox Code Playgroud)