Why does the top-level "catch" default to halt(0) instead of halt(1)?

25 views
Skip to first unread message

Peter Ludemann

unread,
Jan 22, 2019, 2:34:41 PM1/22/19
to SWI-Prolog
It's easy enough to add this (although less easy to find the hints in the documentation), but why doesn't SWI-Prolog does the following by default? (It's really nice to have non-zero error messages when running scripts from a Makefile.)

main :-
    catch_with_backtrace(main2,
                         Error,
                         ( print_message(error, Error),
                           halt(1) )),
    halt(0).

Raivo Laanemets

unread,
Jan 25, 2019, 4:35:41 AM1/25/19
to SWI-Prolog
I think the reason is to always expect a human at the console as the most common Prolog use case is an interactive session. Failing directives and even syntax errors are handled the same, they just emit a warning and won't halt the process. I have implemented some code that checks for load-time warnings and syntax errors and shuts down the process if that is so (for running SWI through spawn/exec and similar).

Peter Ludemann

unread,
Jan 25, 2019, 12:24:16 PM1/25/19
to Raivo Laanemets, SWI-Prolog
After a bit more experimentation, it turns out that the "initialization" directive does result in a non-zero return code for errors -- running a program with "?-" in it from the command line gives a zero return code, presumably because it's treated like a REPL and EOF executes halt(0).

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages