Prolog処理系のAPIがどうなってたのかちょっと調べてみていたら、SWI-Prologの対話インタフェースでの挙動が何やら怪しかったのでメモ。
ゴール列asserta(neko(tama)), neko(X), write(X), nl, halt
をコマンドライン引数や対話インタフェースで与えてみて挙動を見てみる。
試してみたのは以下のとおり。
- GNU Prolog
- Prolog Cafe
- SWI-Prolog (←対話インタフェースでなんか挙動が変。)
GNU Prolog
コマンドライン引数
$ LINEDIT='gui=no' gprolog --init-goal 'asserta(neko(tama)), neko(X), write(X), nl, halt'
tama
対話インタフェース
$ gprolog
GNU Prolog 1.4.4 (64 bits)
Compiled Nov 21 2013, 20:40:25 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?- asserta(neko(tama)), neko(X), write(X), nl, halt.
tama
バージョン
$ gprolog --version
Prolog top-Level (GNU Prolog) 1.4.4
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
GNU Prolog comes with ABSOLUTELY NO WARRANTY.
This is free software; see the source or the file
named COPYING for copying conditions.
Prolog Cafe
コマンドライン引数
ゴール列の指定は非対応。アリティが0の述語名の指定のみ対応しているとのこと。以下はヘルプの引用です。
$ PLCAFEDIR="/Users/masayuki/git/plcafe" ./bin/plcafe -h
Usage: ./bin/plcafe [-options] [class] [args...]
where options support:
-h -help : print this help
-v -verbose : enable verbose output
-cp -classpath <class search path of directories and zip/jar files>
: A : separated list of directories and zip/jar files.
-rt -runtime : boot a runtime environment,
: not including compiler system
-t -toplevel <predicate name possibly with package name>
: set toplevel goal limited to atom
: (ex. -t main)
: (ex. -t package:main)
: Note that class and args must be empty.
-J option : option must be enclosed by '.
: pass option to the Java Virtual Machine
: (ex. -J '-Xmx100m -verbose:gc')
対話インタフェース
$ PLCAFEDIR="~/git/plcafe" ./bin/plcafe
Prolog Cafe 1.2.5 (mantis)
Copyright(C) 1997-2009 M.Banbara and N.Tamura
| ?- asserta(neko(tama)), neko(X), write(X), nl, halt.
tama
バージョン
$ PLCAFEDIR="/Users/masayuki/git/plcafe" ./bin/plcafe -t 'halt'
Prolog Cafe 1.2.5 (mantis)
Copyright(C) 1997-2009 M.Banbara and N.Tamura
SWI-Prolog
コマンドライン引数
$ swipl --quiet -t 'asserta(neko(tama)), neko(X), write(X), nl, halt'
tama
対話インタフェース
対話インタフェースを起動してから、トップレベルにゴールを与えた場合はエラーが出てしまう。 ゴール列内でasserta/1した節を取り出せない(- -;)
$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.6.4)
Copyright (c) 1990-2013 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).
?- asserta(neko(tama)), neko(X), write(X), nl, halt.
ERROR: toplevel: Undefined procedure: neko/1 (DWIM could not correct goal)
?-
バージョン
$ swipl -v
SWI-Prolog version 6.6.4 for x86_64-darwin13.0.0
OS
参考情報として記載します。
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.2
BuildVersion: 13C1021
$ uname -v
Darwin Kernel Version 13.1.0: Wed Apr 2 23:52:02 PDT 2014; root:xnu-2422.92.1~2/RELEASE_X86_64