Hi everyone,
I have the feeling that the first usage of a bang in a rule makes the following uses meaningless, but if this is the case then I don't understand why this predicate would be useful: https://github.com/LPCIC/elpi/blob/master/src/builtin.elpi#L787. Could someone clarify for me?
pred do i:list prop.
do [].
do [H | L] :- H, do L.
/*
If I correctly understand your question, the
my-do! predicate below does what you are saying:
it uses the bang only once after the
prop in the head of the list and then runs the remining props
*/
pred my-do! i:list prop.
my-do! [].
my-do! [H|L] :- H, !, do L.
pred a o:int.
a 0 :- print "first 0".
a 0 :- print "0 again".
a 0 :- print "0 uff".
a 1 :- print "first 1".
a 1 :- print "1 again".
a 1 :- print "1 uff".
main :-
L = [a 0, a 1, fail],
print "=====================================",
% With the std.do! below, I commit the first solution of any prop in the list and never backtrack
% Therefore, only `first 0` and `first 1` are printed,
% that is when I reach `fail` (the last prop in L), I can't backtrack, since there are no
% choice points left
(std.do! L; true),
print "=====================================",
% In the following line, `first 0` and `first 1` are printed.
% When I reach `fail`, there is a choice point
% for `a 1`, the one that prints `1 again`.
% Then, I go forward, I hit `fail` again and the bracktrack
% will print `1 uff`.
% Again I reach fail, and since I have exausted all the choice points of `a 1`
% and since I have cut away all the choice points on `a 0`, I exit the progam.
(my-do! L; true),
print "=====================================",
% Finally the following line shows you all the possible backtracks
% if no bang is inserted
(do L; true).
As you can see, using the bang 0, 1 or n times changes the behaviour of the program.
Am I clarifying your question ?
Yes! I understand now, thanks!
Last updated: Oct 13 2024 at 01:02 UTC