Next: Undefined Predicates, Previous: Queries and Directives, Up: Run Intro [Contents][Index]
Syntax errors are detected during reading2.
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, then
you can use
consult/1
3
to load the code and then 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 predicates
read/[1,2]
normally raise an exception on syntax errors (see ref-ere). The behavior is controlled by the Prolog flagsyntax_errors
.
The SICStus Prolog IDE (see SPIDER) will show syntax errors and many other programming errors directly in the editor, while the code is edited, without loading the code.
By default, e.g. when using [myprog]
, code is compiled.
Compiled code cannot be listed with listing/1
.
Using consult([myprog])
ensures that the code is interpreted, making it available for listing with listing/1
.