[comp.lang.prolog] "clause" in sbprolog? breadth-first evaluation?

phil@rice.edu (William LeFebvre) (07/08/88)

The book "The Art of Prolog" by Sterling and Shapiro refers to a system
predicate "clause" which is defined as follows:

"The goal 'clause(Head, Body)?' must be called with 'Head' instantiated.
The program is searched for the first clause whose head unifies with
'Head'.  The head and body of the clause and then unified with with 'Head'
and 'Body'.  On backtracking, the goal succeeds once for each unifiable
clause in the procedure."

Great.  Does Stony Brook Prolog have something comparable?  I've been
looking and I can't find it.  I am trying to write a meta-evaluator for a
specific subset of Prolog programs that does breadth first evaluation
rather than Prolog's depth first.  But in order to write it I'm pretty
sure that I need something like "clause".  Can anyone help?

The routines in $call cheat and call a builtin to do the dirty work.  I
know I can add my own builtins---can I add one that will hook me into the
unification code?

Or, is it possible to use a separate prref and use $db_get_clauses to get
the job done?

			William LeFebvre
			Department of Computer Science
			Rice University
			<phil@Rice.edu>

ok@quintus.uucp (Richard A. O'Keefe) (07/09/88)

In article <1630@kalliope.rice.edu> phil@rice.edu (William LeFebvre) writes:
>[There is a standard built-in state function clause/2]
>Great.  Does Stony Brook Prolog have something comparable?  I've been
>looking and I can't find it.  I am trying to write a meta-evaluator for a
>specific subset of Prolog programs that does breadth first evaluation
>rather than Prolog's depth first.  But in order to write it I'm pretty
>sure that I need something like "clause".  Can anyone help?

If you look in the file modlib/src/$assert.P you will see that SB-Prolog's
assert* family transforms clauses quite substantially before storing them;
clause/2 would have to undo this transformation.  At first I meant to remind
you of the built-in predicate retract(Clause) which is supposed to pattern
match against the entire clause being retracted, then I noticed the fine
print in the SB-Prolog manual which says that the SB-Prolog version only
matches the Head.  (You will also notice near the beginning of the SB-Prolog
manual a statement that listing/1 is not yet supplied: it's pretty safe to
conclude from that and the behaviour of retract/1 that you might as well
stop looking.)

I suggest that you would be better off not using clause/2 even in Prologs
which have it.  The usual Prolog notation is "defaulty", that is, the system
only knows that p(X,Y) is a call to a user-defined predicate after it has
checked that it isn't something else.  You can obtain a much more efficient
interpreter (and a more beautiful one) by translating the clauses to an
explicit representation.  E.g. you might like to turn
	path(From, To) :- arc(From, Next), path(Next, To).
into
	rule(path(From,To), [arc(From,Next),path(Next,To)]).

With a little care, you might be able to push quite a bit of the
interpreter's work into the translation.