Linux Ubuntu 中的 Prolog 编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20447974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:34:28  来源:igfitidea点击:

Prolog Programming in Ubuntu

linuxubuntuprologswi-prolog

提问by octain

I have an interest in playing and fuxing with prolog, I have installed the swi-prolog and added the repository, just in case anyone is interested on which one commands I used:

我对使用 prolog 进行播放和修复很感兴趣,我已经安装了 swi-prolog 并添加了存储库,以防万一有人对我使用的哪个命令感兴趣:

% sudo apt-add-repository ppa:swi-prolog/stable
% sudo apt-get update
% sudo apt-get install swi-prolog

How do I actually begin to write prolog codes on my linux machine? for my regular programming I use VIM to write/edit/debug and terminal to compile. Can I use vim to write prolog? How do i compile or use the prolog interpreter(i think that is what it is called)?

我如何真正开始在我的 linux 机器上编写 prolog 代码?对于我的常规编程,我使用 VIM 编写/编辑/调试并使用终端进行编译。我可以用vim写prolog吗?我如何编译或使用 prolog 解释器(我认为这就是它的名字)?

采纳答案by Christian Fritz

Yes, you can use any text editor, incl. VIM. Once you have written a Prolog source file, say, file.pl, you can load it into SWI-Prolog like so:

是的,您可以使用任何文本编辑器,包括。维姆。编写 Prolog 源文件后,例如file.pl,您可以将其加载到 SWI-Prolog 中,如下所示:

swipl -s file.pl

This will compile your file and take you to an interactive shell where you can then ask queries against the definitions in your file.

这将编译您的文件并将您带到一个交互式 shell,然后您可以在其中对文件中的定义进行查询。

If you want to use your Prolog program in batch mode, you can use:

如果要以批处理模式使用 Prolog 程序,可以使用:

swipl -s file.pl -t goal

where goalis the goal/query you want to evaluate. Note that in this case you won't be getting the option to ask for alternative solutions.

goal您要评估的目标/查询在哪里。请注意,在这种情况下,您将无法获得寻求替代解决方案的选项。

回答by magus

On Ubunutu, I started off using emacs, which at least does syntax highlighting:

在 Ubunutu 上,我开始使用 emacs,它至少做了语法高亮:

http://www.swi-prolog.org/FAQ/GnuEmacs.html

http://www.swi-prolog.org/FAQ/GnuEmacs.html

(2 emacs suggestions on that page ^)

(该页面上有 2 个 emacs 建议 ^)

But now I use prolog in anger, I use an Eclipse plugin called PDT:

但是现在我愤怒地使用prolog,我使用了一个名为PDT的Eclipse插件:

http://sewiki.iai.uni-bonn.de/research/pdt/docs/v2.1/start

http://sewiki.iai.uni-bonn.de/research/pdt/docs/v2.1/start

Especially useful is the real-time line by line debug and trace, so you can step into, step over individual predicates, monitor variables names etc.. just like an other real IDE you would find in eclipse.

特别有用的是实时逐行调试和跟踪,因此您可以单步执行、单步执行单个谓词、监视变量名称等。就像您在 eclipse 中找到的其他真实 IDE 一样。

Probably only worth installing if you're going to use it a LOT, since the install is a lot of work, but it's a great IDE.

如果您要大量使用它,可能只值得安装,因为安装工作量很大,但它是一个很棒的 IDE。

But if you like your low level editors like VIM, you will have to use the debug and trace tools built into swi-prolog, see:

但是,如果您喜欢像 VIM 这样的低级编辑器,则必须使用 swi-prolog 中内置的调试和跟踪工具,请参阅:

http://www.swi-prolog.org/pldoc/man?section=debugger

http://www.swi-prolog.org/pldoc/man?section=debugger

To work out how the strange and beautiful prolog interpreter works, using a tracer of some kind is a must-have.

要弄清楚奇怪而漂亮的 prolog 解释器是如何工作的,必须使用某种跟踪器。

回答by majik

I personally use gprolog or swipl in the interpreted environment. So you write facts and rules in a mydb.pl file, and open the interpreter in the same directory. Once the prompt shows up you can query

我个人在解释环境中使用 gprolog 或 swipl。因此,您在 mydb.pl 文件中编写事实和规则,并在同一目录中打开解释器。出现提示后,您可以查询

['mydb.pl'].

for loading your database. now you can either see the warnings\errors or start querying from inside the prolog interpreter.

用于加载您的数据库。现在您可以看到警告\错误或从 prolog 解释器内部开始查询。

回答by mohit saraswat

You can use any text editor to write your code. Just make sure to save your code with the .plextension like fibo.pl. After that open the terminal and go to the location where you have saved your code. After that type prolog After that write the name of your file without .plextension and end it with .['fibo'].and press return

您可以使用任何文本编辑器来编写代码。只需确保使用.pl扩展名保存您的代码,例如fibo.pl。之后打开终端并转到您保存代码的位置。在那之后输入 prolog 之后,写下没有.pl扩展名的文件名并以.pl结尾['斐波那契']。然后按回车

Eg - cd /home/student/14917
prolog
['fibo'].

例如 - cd /home/student/14917
prolog
[' fibo ']。



Here fibo.plis my program name

这里fibo.pl是我的程序名称

回答by JCR

I use SWI prolog with Sublime Text on mac. Works really nice. In Sublime Text you just hit cmd - B to run the code, and the output appears in a window within Sublime Text. There is a package for it here.

我在 mac 上使用带有 Sublime Text 的 SWI prolog。效果很好。在 Sublime Text 中,您只需按 cmd - B 运行代码,输出就会出现在 Sublime Text 的窗口中。有一个包就在这里