I'm trying to learn SWI prolog, but my simple program fails when I believe it should succeed.
%My code:
orthogonal((X1,Y1,Z1),(X2,Y2,Z2)) :- (X1*X2)+(Y1*Y2)+(Z1*Z2)==0.
integerVector((X,Y,Z)) :- integer(X),integer(Y),integer(Z).
?-orthogonal((1,0,0),(0,0,1)).
I press compile Buffer in the pseudoemacs window and the output is:
% [PATH].pl compiled 0.00 sec, 136 bytes
ERROR: emacs_prolog_mode ->error_at_location: Argument 1 (int): `int' expected, found `@11470948?start'
ERROR: emacs_prolog_mode ->error_at_location: Argument 1 (int): `int' expected, found `@11470948?start'
Warning: [PATH]s.pl:5:
Goal (directive) failed: user:orthogonal((1,0,0), (0,0,1))
Prolog uses the unification technique, and it is a very general form of matching technique. In unification, one or more variables being given value to make the two call terms identical.
body the last part of a Prolog rule. It is separated from the head by the neck symbol, written as :- . It has the form of a comma-separated list of goals, each of which is a the name part of a functor, possibly followed by a comma-separated list of arguments, in parentheses.
or, logical disjunction, ; The logical conjunction (logical-and, ∧) of goals is achieved in Prolog by separating the goals by commas: happy(X) :- rich(X), famous(X). says that X is happy if X is rich and X is famous.
You have used (==)/2
in place of (=:=)/2
which evaluates its arguments as arithmetic expressions.
You can use (X,Y,Z)
, but it isn't a triple as in e.g. Haskell. To see this:
?- write_canonical((1,2,3)).
','(1,','(2,3))
?- (1,2,3) = (X,Y).
X = 1,
Y = (2,3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With