That is, the DCG clause:
a -> b, ! ; c. |
gets expanded to the clause:
a(A, B) :- b(A, C), !, C = B ; c(A, B). |
and not to the clause:
a(A, B) :- b(A, B), ! ; c(A, B). |
as in Quintus, SICStus and C Prolog.
The latter expansion is not just optimized, but it can have a different (unintended) meaning if a/2 is called with its second argument bound.
However, to obtain the standard expansion provided by the other Prolog systems, the user can simply execute:
set_dcg_style(standard). |
To switch back to the XSB-style DCG's, call
set_dcg_style(xsb). |
This can be done anywhere in the program, or interactively. By default, XSB starts with the XSB-style DCG's. To change that, start XSB as follows:
xsb -e "set_dcg_style(standard)." |
Problems of DCG expansion in the presence of cuts have been known for a long time and almost all Prolog implementations expand a DCG clause with a '!'/0 in its body in such a way that its expansion is steadfast, and has the intended meaning when called with its second argument bound. For that reason almost all Prologs translate the DCG clause:
a -> ! ; c. |
to the clause:
a(A, B) :- !, B = A ; c(A, B). |
But in our opinion this is just a special case of a '!'/0 being the last goal in the body of a DCG clause.
a -> (true -> X = f(a) ; not(p)). |
gets expanded to the clause:
a(A,B) :- (true(A,C) -> =(X,f(a),C,B) ; not p(A,B)) |
and not to the clause:
a(A,B) :- (true(A,C) -> =(X,f(a),C,B) ; not(p,A,B)) |
that Quintus Prolog expands to.
However, note that all non-control but standard predicates (for example true/0 and '='/2) get expanded if they are not enclosed in curly brackets.