On Wednesday, 23 February 2022 at 23:50:41 UTC+1,
solitary....@gmail.com wrote:
> I am a newbie in Prolog and I've been reading the Prolog section in "Seven Languages in Seven Weeks".
A pretty absurd proposition if you ask me. :) All the more so for Prolog in
particular, which is utterly "exotic", indeed neither imperative nor functional.
> He introduces some basic elements of the language with this file:
>
friends.pl
> ---------------
> likes(wallace, cheese).
> likes(grommit, cheese).
> likes(wendolene, sheep).
>
> friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
>
> When I consult that with Gnu Prolog (which variant the author also uses), I get 2 compile errors:
>
> | ?- consult('D:/Steve - D/Documents - D/GNU-Prolog/
friends.pl').
> compiling D:/Steve - D/Documents - D/GNU-Prolog/
friends.pl for byte code...
> D:/Steve - D/Documents - D/GNU-Prolog/friends.pl:1:6: syntax error: . or operator expected after expression
> D:/Steve - D/Documents - D/GNU-Prolog/friends.pl:5:14: syntax error: . or operator expected after expression
> 2 error(s)
> compilation failed
>
> (15 ms) no
>
> For the life of me it looks like I typed in the same example as in the book and that there should be no errors.
>
> Any help would be appreciated.
Surely works for me:
---------------------------------------------------
GNU Prolog 1.5.0 (64 bits)
Compiled Jul 8 2021, 12:33:56 with cl
Copyright (C) 1999-2021 Daniel Diaz
| ?- [user].
compiling user for byte code...
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).
friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
user compiled, 6 lines read - 881 bytes written, 8350 ms
(16 ms) yes
| ?-
---------------------------------------------------
(There is ctrl+D after the code to close the user stream.)
Consulting from a file would be equivalent, so maybe you have extra-characters
in the file you haven't noticed or some file encoding issues (i.e. it's not really a
plain text file): that Prolog code anyway is valid.
Rather, the code doesn't seem correct: that \+(X=Y) in that position just won't
cut it... but I do not have the book and I can't guess what's going wrong there,
unless you are simply miscopying.
Julio