AI 作业开玩有趣的prolog,记录下配置 mac os 10.12.2 环境下配置 prolog 吧。
主流是安装 SWI-Prolog,链接在这里,注意这里是开发版的,亲测稳定版对本机(10.12.2)支持不好,内置 terminal 莫名其妙黑屏。安装开发版,你也可能需要安装XQuartz(X11).
安装就绪,打开SWI-Prolog,载入测试文件,
?- ['/..../family.pl'].
输出 true,即是成功。
作为程序猿,APP的 GUI显然不能显示我们的逼格,大多情况下还是需要请出 Terminal。
依赖SWI-Prolog 修改环境变量是一个办法,brew 安装是一个更普世的办法,
Simply go to terminal window and type in:
brew tap homebrew/x11
after the above command executes, enter:
brew install swi-prolog --HEAD
and now swipl
should work:
Maryams-MacBook-Pro:~ maryam$ swipl
returns
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.3)
Copyright (c) 1990-2015 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.
For help, use ?- help(Topic). or ?- apropos(Word).
Yay! ready to go. Let's test this:
?- ['/..../family.pl'].
true.
以前用 OCaml 的时候,接触了 Emacs这一神器,对于 Prolog 我们依然可以信赖它,参考教程在
这里
- Download the file
prolog.el
from https://bruda.ca/emacs/prolog_mode_for_emacs and save it in your load-path
so that Emacs can find it.
- Optionally, you can byte-compile
prolog.el
for better performance. Load prolog.el
into Emacs and do M-x byte-compile-file RET
.
- Add the following lines to
~/.emacs
(~/_emacs
on Windows):(autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t)
(add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
Where is ~/_emacs?
~ is a shortcut for the home directory, on Windows it is system and language specific. It may be for example C:\
orC:\Dokumente
. The best way to find "~" is: select "Files->Open.." and enter "~". Then Emacs prints the directory name and contents.
- Customize the Prolog mode. The following page explains how to enable electric indentation, syntax checking and PceEmacs-style comments: https://www.metalevel.at/pceprolog/
- ediprolog allows you to interact with SWI-Prolog in all Emacs buffers. You can quickly consult buffers and regions, and run queries that are embedded in your source files. ediprolog is available from: https://github.com/triska/ediprolog