2010/11/12 Fernando Sáenz Pérez <fernan(a)sip.ucm.es>:
Hello, It seems to be an issue in the top-level when loading the following program (say, p.pl):
:- initialization(main).
main :- repeat, read(X), X==stop.
By submitting 'ensure_loaded(p)' the program does not stop when reading the term 'stop'. However, the very same program without the initialization directive does return to the top-level when explicitly called with the goal 'main'. Is this a bug or a feature?
Dear Fernando,
there is an implicit failure after the execution of goals in 'initialization' directives. I have looked into the documentation but I found no mention to this behavior, which I would call a bug.
Temporary work-arounds are:
a) :- initialization((main, !)).
b) make sure that the goal in the initialization directive is semi-det (1 solution at most).
c) write your failure loops as:
main :- ( repeat, Loop, ExitCond, ! ; true ).
Cheers