next up previous contents index
Next: Interaction of Definite Clause Up: Definite Clause Grammars Previous: Definite Clause Grammar predicates   Contents   Index


Two differences with other Prologs

The DCG expansion provided by XSB is in certain cases different from the ones provided by some other Prolog systems (e.g. Quintus Prolog, SICStus Prolog and C-Prolog). The most important of these differences are:
  1. XSB expands a DCG clause in such a way that when a '!'/0 is the last goal of the DCG clause, the expanded DCG clause is always steadfast.

    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.

  2. Most of the control predicates of XSB need not be enclosed in curly brackets. A difference with, say Quintus, is that predicates not/1, ${\tt '\backslash+'/1}$, or fail_if/1 do not get expanded when encountered in a DCG clause. That is, the 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.


next up previous contents index
Next: Interaction of Definite Clause Up: Definite Clause Grammars Previous: Definite Clause Grammar predicates   Contents   Index
Baoqiu Cui
2000-04-23