Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

How to input while using predicate 'read'?

Since be new to Prolog, these days I was doing the exercises following the book Adventure in Prolog.
But now I meet with an newbie question, how to input while using 'read'.

?- read(X).

X = a ;
?- read(Y).

Y = b ; . ;
?- read(Z).
test a test.
Unexpected operator
While executing: read_term$/3
Read buffer: test a **NEAR HERE** test.

File: user_in Line 8
Call stack:
- read_term/3;- catch/3;+ catch/3;--- top of stack ---


Since Adventure in Prolog is my first Prolog book, I even don't know how to input while using read.
An 'Enter' can not finish the input, so I tries a '.', and it seems work.
When I tries ';', more input lines seems appeared, and only double '.' can end the input.
And when I tries to add a space between the words I inputed, it reports syntax_error 407.

What cause the problem? And by the way, where I can find a complete introduce for all the Amzi! Prolog Builtin Predicates?


  • read/1 reads a valid Prolog term, ending with a period. So it must be formatted as if you were writing it in code. So read(X) will bind X to the term if it's valid. Otherwise you get an error. It gets a bit confusing when you use 'operators'. When you read about operators you will understand. The ';' is an operator in Prolog.

    The build-in predicates of Amzi! are all in It should be in your distribution as well. They are organized by category, but if you click 'index' on the table of content you will see an alphabetical listing.
  • Examples: read(X) will read: sue. (an atom), 47. (an integer), location(kitchen, sink). (a term). X. (a variable) a + b. (a term using an operator). Anything else is an error.
Sign In or Register to comment.