Subject: Re: term comparison in foreign code

From: Jan Wielemaker <[email-masked]>
Date: Tue, 18 Apr 2000 15:03:34 +0200

> How, from within foreign code, can we determine whether two variables
> are shared?
> 
> Is PL_compare() the only way?
> 
> Or is there some identifier, unique to each distinct variable, which
> can be used e.g. to maintain a map of variables-seen-so-far when
> traversing a term?

Term references are numbers providing an offset to the base of the
local stack where there is a Prolog term which, in the case of
variables, will often be a `reference'.  Variables have no unique
id with public access (except for writing the term and using the
_[LG]<N> name).

PL_is_variable() and PL_compare() are your only choices.  PL_compare()
is very quick (unless it needs to go deeply into compound terms of
course).

A unique id would actually be hard.  Returning an offset to the stack
location would be an option, but it is not safe: a garbage collection
can change the offset at any time.

	Regards --- Jan