Re: setarg/3: Meaning of "aliased"

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Wed 07 Sep 2005 03:06:02 PM GMT
Message-ID: <431F01DA.8020206@icparc.ic.ac.uk>
Ulrich Scholz wrote:
> Dear all,
> 
> I'm not exactly sure about the meaning of "aliased" and "location" in the
> description of setarg/3:
> 
>   "In particular, it must be assured by the programmer that [...] the old
>    argument was not aliased to some other location."
...

> Maybe this refers to the fact that in the following example X remains
> unified with 1 while the term t(1) is changed to t(2).
> 
> [eclipse 29]: X=1, T=t(X), setarg(1,T,2).
> 
> X = 1
> T = t(2)
> Yes (0.00s cpu)

On the contrary: it would be an example of aliasing if X had changed
its value as a side effect of the setarg.

The situation is called aliasing because it would indicate that
the same memory location was known under two names, namely
"X" and "the first argument of T", and changing one of them
inadvertently changed the other.


Kish Shen wrote:
> 
> If what you want is some mutatable storage, ECLiPSe provide other safer
> alternatives such as global references.

Global references aren't really giving you the same functionality.

One can say in general that the use of setarg/3 is safe as long as
you only work with nonvariable terms. |I.e. you should initialise your
structure arguments with a nonvariable term, and only setarg them to
other nonvariable terms. This excludes the kind of tricky example you
had above.


-- 
  Joachim Schimpf              /             phone: +44 20 7594 8187
  IC-Parc                     /      mailto:J.Schimpf@imperial.ac.uk
  Imperial College London    /    http://www.icparc.ic.ac.uk/eclipse
Received on Wed Sep 07 16:12:22 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:39 PM GMT GMT