Syntax errors are detected during reading. Each clause,
directive or, in general, any term read in by the
built-in predicate read/1
that fails to comply with
syntax requirements is displayed on the standard error
stream as soon as it is read, along with its position in the input
stream and a mark indicating the point in the string of symbols
where the parser has failed to continue analysis, e.g.:
| memb(X, X$L). ! Syntax error ! , or ) expected in arguments ! in line 5 ! memb ( X , X ! <<here>> ! $ L ) .
if ‘$’ has not been declared as an infix operator.
Note that any comments in the faulty line are not displayed with the
error message. If you are in doubt about which clause was wrong
you can use the listing/1
predicate to list all the
clauses that were successfully read in, e.g.:
| ?- listing(memb/2).
Please note: The built-in predicatesread/[1,2]
normally raise an exception on syntax errors (see ref-ere). The behavior is controlled by the Prolog flagsyntax_errors
.