In article <1994Jan17.095242.18410@aifh.ed.ac.uk> dcu@aifh.ed.ac.uk () writes:
Hullo POP people,
One of those Friday afternoon confusions I would really appreciate a
clear answer to. Consider the following:
constant a1;
[1 2 3]->a1;
define binki(lst);
lvars lst;
10->hd(lst);
enddefine;
When I run binki() it changes the value of the constant a1. I'm sure this is
what everyone apart from me would expect (even on a Friday).
So WHY does this happen and HOW do I stop it?
``constant'' just means that you can't assign to the constant'ed thing (here,
a1) except once at top-level. (My style guide strongly insists that you
write the above as ``constant a1 = [1 2 3]'', to make the binding of value
to variable explicit). It doesn't mean that the value bound can't be changed.
In general, Pop doesn't have immutable values; there are special provisions for
systemy things being stored in write-protected store, but nothing the average
user can do to say ``this list is immutable'' [I think].
So, you have a choice. Did you really intend to have an immutable list? Then,
sorry, tough. You can't have one.
Did you want an immutable sequence of items? Then you'll have to make a new
record or vector class with no updaters. If you want some instances of the
structure to be writeable, and others not, you'll have to have a ``writeable''
flag somewhere.
Did you intend each call to ``binki'' to work on a new list? Then, as you
noted, ``copylist'' is the thing for you.
And remember: values are independant from variables; ``constant'' applies only
to the binding of value to variable, not to the contents of the value.
--
Regards, | ``In fingers of trees, and valleys of gold | Judy Tzuke
Kers. | I watch as you outshine the charlatan foe.'' | Higher & Higher
|