SWI-Prolog 1.2
Focal point
- Knowledge base: A collection of Facts and Rules.
- Syntax(句法) : Facts, Rules, Queries 的組成術語 (terms)。
- Atoms
- Numbers
- Variables
--
Atoms (原子) 符合以下任一條件:
- 由大寫/小寫字母、數字或是底線組成的字串 (string) 或字符 (characters) ,並以小寫字母為開頭。
- 單引號框起來的任意排列 (arbitrary sequence) 字符
- 在 Prolog 中已被賦有特殊意義的字符。例如:
@=
,:-
,;
,,
(上述字符代表的意思請參考 SWI-Prolog 1的筆記)
Numbers (數值)
E.g. float, integer.
Variables (變數)
- 由大寫/小寫字母、數值、底線組成的字串或字符,並以大寫字母或底線為開頭。
_
為特殊變數,稱為 anonymous variables (匿名變數)-> Chapter 4 //TODO
Complex terms
- Building out of a functor (函式) directly followed (can't have a space between the functor and the parenthesis) by a sequence of arguments which are put in ordinary parentheses and separated by commas. E.g.
happy(abby)
is a complex term: its functor is happy and its argument is abby. - The functor must be an atom.
- Nesting (嵌套) complex terms inside complex terms are allowed.
- Complex term 的參數數目稱為 arity. E.g. loves(abby, miku) is a complex term of arity 2.
- 透過 suffix / followed by a number 來指出 predicate's arity. Prolog 會視相同 functor 但 arity 不同者為不同。(待補充)
Built-in Prolog predicates
listing.
: 顯示當前 knowledge bases 的內容。listing[Predicate].
:顯示所有與該 predicate 有關的資訊。halt.
: 停止 Prolog。[KB NAME].
or['C:.....KB NAME.pl'].
: 載入其他 knowledge base 到當前的 .pl 檔。- 注意:Perl scripts 的 suffix 也是 .pl。
留言
張貼留言