[REBOL] Re: Objects, references & values
From: rotenca:telvia:it at: 18-Dec-2001 19:40
Hi Robert,
> IMO the concept of a get-path is missing. I would like to write:
>
> value: to-get-path obj1/name
>
> This should result in a reference to obj1/name and not the value.
If i have understand well what you ask, this my answer:
nameref: in obj1 'name
Now 'nameref is a pointer to a word which is linked to the field called "name"
in the object 'obj1.
obj1/name: "robert3"
== "robert3"
To retrieve the changed value:
>> get nameref
== "robert3"
To change it:
set nameref "robert4"
== "robert4"
Proof:
>> get nameref
== "robert4"
>> obj1/name
== "robert4"
Another method:
x: bind [name] in obj1 'self
Now x is a block which contains as the first item the word 'name linked to the
object obj1:
x: bind [name] in obj1 'self
== [name]
>> get first x
== "robert4"
I can reach the same result inserting the word pointed by nameref in a void
block, the word always conserves its link with obj1:
>> x2: head insert copy [] nameref
== [name]
>> get first x2
== "robert4"
or with reduce:
>> x3: reduce [nameref]
== [name]
>> get first x3
== "robert4"
If we want to make things more difficult, we can use the third of obj1:
>> third obj1
== [name: "robert4" note: "Rebol"]
>> set first third obj1 "robert5"
== "robert5"
>> third obj1
== [name: "robert5" note: "Rebol"]
>> get nameref
== "robert5"
>> get first x
== "robert5"
>> get first x2
== "robert5"
>> get first x3
== "robert5"
---
Ciao
Romano