[net.lang.prolog] Definition of 'numbervars/3'

hopp@nbs-amrf.UUCP (Ted Hopp) (03/05/85)

I recently obtained a listing of Dave Warren's WARPLAN planner and
put it up on our system, running C-Prolog 1.3.  Everything went
smoothly except for a predicate "numbervars/3", which was evidently
part of the prolog he was using (DEC-10 Prolog?), but is not part
of our Prolog.  I did find a description of it, which described it
something like this (this is off the top of my head):

	numbervars(T,N,M)

	Binds all variables in T to special terms such that
	the variables print as consecutive integers from N to M.

I defined a numbervars and it seems to work, but I have no idea if
it is right.  My definition is:

	numbervars(T,N,N) :- atomic(T),!.
	numbervars(T,N,M) :- var(T),!,M is N+1,T=M.
	numbervars([H|T],N,M) :- !,numbervars(H,N,M1),numbervars(T,M1,M).
	numbervars(T,N,M) :- T=..[_|Args],!,numbervars(Args,N,M).

That is, I bind each variable in T to an integer.  Is this, for
practical purposes, different that binding to "special terms"
that print as integers?  In particular, the goal:

	numbervars(X,0,1),numbervars(Y,0,1),X=Y.

succeeds with my definition; does it with the built-in numbervars
on those Prologs that have it?

As a secondary question, if my definition is operationally correct,
is there a more efficient definition?  WARPLAN seems to spend a lot
of time numbering variables, and it would be nice if this were as
efficient as possible.

-- 

Ted Hopp	{seismo,umcp-cs}!nbs-amrf!hopp