正如指出的@false後,你有語法錯誤:
Quetzalcoatl$ cat <<.. > pl.pl
> is_true(P,P):-fact P.
> is_true(C,C<=ProofTreeA):-if A then C, is_true(A,ProofTreeA).
> is_true(P1 and P2, ProofTree1 and ProofTree2):-(P1<=ProofTree1),(P2<=ProofTree2).
> is_true(P1 or P2, ProofTree1):-(P1 or P2<=ProofTree1).
> is_true(P1 or P2, ProofTree2):-(P1 or P2<=ProofTree2).
> ..
Quetzalcoatl$ gprolog --init-goal "['pl.pl']"
compiling pl.pl for byte code...
pl.pl:1:20: syntax error: . or operator expected after expression
pl.pl:2:12: syntax error: , or) expected
pl.pl:3:12: syntax error: , or) expected
pl.pl:4:12: syntax error: , or) expected
pl.pl:5:12: syntax error: , or) expected
5 error(s)
compilation failed
warning: command-line goal '[''pl.pl'']' failed
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 17:26:17 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?-
Prolog是-kind OF-聲明式編程......試着像那樣思考。
這是一個使用gnu-prolog語法的版本(gprolog manual)。我不明白你的邏輯,所以你應該驗證。
Quetzalcoatl$ cat pl.pl
%you should be aware of the signatures of your rules, e.g. is_true(+fact,?fact), is_true(?fact,?fact)
:-op(800,xfy, and).
:-op(801,xfy, or).
is_true(P,P):-nonvar(P),P. %P should be bounded to a fact (e.g. fact/1) existing in your knowledge base of facts
is_true(C,ProofTreeA):- A , [email protected]=<ProofTreeA, is_true(A,ProofTreeA). %A is ubounded ?
%'if A then C' ---> 'A,C' %assuming A is a fact in the knowledge base
is_true(and(P1, P2), and(ProofTree1 , ProofTree2)):-([email protected]=<ProofTree1),([email protected]=<ProofTree2).
is_true(or(P1 , P2), ProofTree1):-P1 @=< ProofTree1 ; P2 @=< ProofTree1.
%s_true(or(P1 , P2), ProofTree2):-(P1 or P2<=ProofTree2). this rule is the same than the above one
Quetzalcoatl$ gprolog --init-goal "['pl.pl']"
compiling pl.pl for byte code...
pl.pl compiled, 9 lines read - 1708 bytes written, 4 ms
GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 17:26:17 with /opt/local/bin/gcc-apple-4.2
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?-
語法看起來很不尋常。 「事實」,「<=」,「如果」,「然後」,「和」,「或」必須定義爲運營商。您可能會定義一些額外的運算符。 – false
正如@false指出的那樣,您已經有了自定義的操作符,但您沒有提到過。而你的*有些錯誤*有點含糊。發佈問題時最好顯示錯誤消息等。 '<='是你定義的一個操作符?如果不是的話,那麼如果你使用它來比較術語,你的'<='應該在Prolog中是@ = <'。 '<='不是Prolog中的內置運算符。 – lurker