Consult parse errors are not excpetions?

Edd Barrett <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi,

I originally noticed this when using the C API, but it can also be seen
by using the swipl interactive interpreter. It is probably easier to
explain using the interpreter.

Look at a normal exception, for example, we call a non-existing
predicate:

---8<---
?- blah(a), writeln(hi).
ERROR: toplevel: Undefined procedure: blah/1 (DWIM could not correct goal)
---8<---

The predicate blah/1 does not exist, and so an exception fires, thus
preventing  the writeln/1 predicate from executing. Fine.

Now consider a theory file with a syntax error in it -- call it a.pl.

---8<---
?- consult(a), writeln(hi).
ERROR: /tmp/a.pl:1:11: Syntax error: Unexpected end of file
% a compiled 0.00 sec, 1 clauses
hi
true.
---8<---

A syntax error occurred, but an exception was not thrown. We can see this
is the case since writeln/1 was executed.

How comes? Should a syntax error not be an exception? There may well be
a good reason for this, but I am curious.

As I said, this can be seen at the C level too. When I use PL_open_query()
followed by PL_next_solution() to initiate 'consult(a)', where a.pl has a
syntax error, I see the syntax error reported on the terminal, but
PL_exception() reports that everything is OK. I have no means by which to
detect the parse error.

Any thoughts on this behaviour?

Thanks

-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.