yap prolog read predicate
-
28-09-2019 - |
Question
I am experimenting with prolog, reading "Programming in prolog using the ISO standard, fith edition". I have installed yap (yet another prolog) on my ubuntu 10.10 Maverick RC system, installed using synaptic. I am running prolog from within emacs23 using prolog-mode.
The following code (from chapter five of book) does not give results as in book:
/* FILE history_base.pl */
use_module(library(lists)) /* to use member/2 */
event(1505,['Euclid',translated,into,'Latin']).
event(1510,['Reuchlin-Pfefferkorn',controversy]).
event(1523,['Christian','II',flies,from,'Denmark']).
mywhen(X,Y):-event(Y,Z),member(X,Z).
% Restoring file /usr/lib/Yap/startup
YAP version Yap-5.1.3
< reading the above file into yap>
?- mywhen("Denmark",D).
no
which is not what the book gives!
Now adding to the file above the line (from the book):
hello1(Event):- read(Date), event(Date,Event).
Gives this error when reading the file into yap
(using "consult buffer" in the prolog menu in emacs):
?- % reconsulting /tmp/prolcomp14814QRf.pl...
SYNTAX ERROR at /tmp/prolcomp14814QRf.pl, near line 3:
use_module( library( lists ) )
< ==== HERE ====>
event( 1505 , [ Euclid , translated , into
, Latin ] ).
% reconsulted /tmp/prolcomp14814QRf.pl in module user, 0 msec 752 bytes
yes
?-
¿Any comments?
Solution
Perhaps you should terminate the use_module(library(lists))
statement with a .
and declare it as a directive, i.e.:
:- use_module(library(lists)).
OTHER TIPS
You have to write Denmark between single quotes instead of double quotes, i.e.:
?- mywhen('Denmark', D).
When you put Denmark between double quotes, the prolog interprets it as a list of character codes instead of an atom, but in the definition of event it is written as an atom (between single quotes).