2
votes

Using SWI Prolog 7.7.2 in Ubuntu Linux, I am trying to run the "talk" module from Pereira and Schieber (Appendix A, http://www.mtome.com/Publications/PNLA/prolog-digital.pdf).

After copying, pasting into a text editor (Sublime), and adjusting line breaks to (mostly) match the original, running swipl, and then ['talk.P'], I am encountering over two dozen "Syntax error: Operator expected" errors, e.g. (with directory location replaced by [...]):

Lines 15-20:

main_loop :-
    write(’>> ’),       % prompt the user
    read_sent(Words),   % read a sentence
    talk(Words, Reply), % process it with TALK
    print_reply(Reply), % generate a printed reply
    main_loop.          % process more sentences

ERROR: [...]/talk.P:16:15: Syntax error: Operator expected

---Line 38:

talk(_Sentence, error(’too difficult’)).

ERROR: [...]/talk.P:38:25: Syntax error: Operator expected

---Lines 76-77:

% Replying to some other type of sentence.
reply(_Type, _FreeVars, _Clause, error(’unknown type’)).

ERROR: [...]/talk.P:77:42: Syntax error: Operator expected

---Lines 87-91:

print_reply(error(ErrorType)) :-
    write(’Error: "’), write(ErrorType), write(’."’), nl.

print_reply(asserted(Assertion)) :-
    write(’Asserted "’), write(Assertion), write(’."’), nl.

ERROR: [...]/talk.P:91:12: Syntax error: Operator expected

---Note I am also encountering ten singleton variable warnings, but am not sure whether this will prove to be a problem or not, e.g.:

---Lines 59-60:

reply(query, FreeVars,
    (answer(Answer):-Condition), Reply) :- Warning: [...]/talk.P:59:  Singleton variables:

[FreeVars,Condition,FreeVarsˆCondition] Warning: [...]/talk.P:59: Singleton variable in branch: FreeVarsˆCondition

---Lines 242-243:

q(S => ‘answer(X)) -->
    whpron, vp(finite, XˆS, nogap).

Warning: [...]/talk.P:242: Singleton variables: [S,X,XˆS]

What do I need to do to get this module up and running?

1
BTW, whitespace does not matter in Prolog. - Tomas By
Need to see more of the file. It's possible that the error around line 16, for example, could be due to a syntax problem several lines earlier. "Singleton" variables are variables that occur once and do not appear to have any use as named variables. Sometimes this is intentional. Most of the time, it's an error on the programmer's part. If it is intentional, the warning can be avoided by using _ or _<whatever_name_you_want> instead. In your case, for some reason, the X and S aren't "visible" in vp(finite, X^S, nogap). Again, could be due to other syntax issues earliler. - lurker
What's the weird quote in front of answer(X)? q(S => ‘answer(X)) ...? - lurker
When you do a copy/paste from PDF or HTML, you need to beware of non-ASCII character sets being used. In your first error, write(’>> ’) is not using ASCII single quotes as required. The text is using another character code to give a single-quote character, not the simple ASCII version. Change these to normal ASCII single quotes, and that error will go away. Same with the other errors. For example, talk(_Sentence, error(’too difficult’)). uses the non-ASCII single quotes. - lurker
lurker, thanks - Tomas By posted the author's code at the link below. I'm new enough to Prolog that as long as I don't see smiley faces in the code, I'm not sure what is valid or isn't - but his reply has allowed me to get it running. - CorvinoDiNevarca

1 Answers

2
votes

There are a couple of problems. The operator values (100, 500 etc) are compatible with older values for the standard operators and should be higher. Also, the back-quote/back-tick (ASCII 96) changed at some point from being a symbol to being a quote character.

I managed to get the files to load in SWI prolog, by changing the operators:

:- op(1000,xfy,&). 
:- op(1010,xfy,=>). 
:- op(200,fx,`).

and giving the command line parameter --traditional (to make back-quote a symbol instead of a quote character).

$ swipl --traditional
Welcome to SWI-Prolog (threaded, 64 bits, version 7.4.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [talk].
true.