From jan@swi.psy.uva.nl  Tue Apr 18 15:03:03 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id PAA19139;
	Tue, 18 Apr 2000 15:03:02 +0200 (MET DST)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id PAA18023;
	Tue, 18 Apr 2000 15:03:34 +0200
Date: Tue, 18 Apr 2000 15:03:34 +0200
Message-Id: <200004181303.PAA18023@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: term comparison in foreign code
To: Paul Singleton <p.singleton@keele.ac.uk>,
        SWI Prolog <prolog@swi.psy.uva.nl>
In-Reply-To: Paul Singleton's message of Tue, 18 Apr 2000 13:45:26 +0100
Phone: +31 - 20 - 525 6121

> 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

