[REBOL] Re: Which? [Object! Block!]
From: cyphre:volny:cz at: 27-Sep-2001 10:06
Hi Ammon and Andrew,
Just one important note...
Your method of adding new value(s) into same object is common but be careful
of clonnig objects when the parent object contains another nested
object(s)!!!
See this example:
>> a: make object! [x: 5 y: make object! [z: 10]]
>> b: make a []
>> probe b
make object! [
x: 5
y:
make object! [
z: 10
]
]
>> a/x
== 5
>> b/x
== 5
>> a/x: 8
== 8
>> b/x ;thats OK
== 5
>> a/y/z
== 10
>> b/y/z
== 10
>> b/y/z: 3
== 3
>> a/y/z ;Ups! both objects 'a and 'b have "shared" nested object 'x which
can lead to problems in yourcode!!
== 3
In that situation you have to make your own function for recursive
re-building of nested objects(could be faster that second solution) or use
this second solution:
>> a: make object! [x: 5 y: make object! [z: 8]]
>> b: do mold a ; "do mold" clones whole object with all its nested objects
;this method is slower when cloning bigger objects
than method of recursion...
>> probe b
make object! [
x: 5
y:
make object! [
z: 8
]
]
>> a/y/z
== 8
>> b/y/z
== 8
>> b/y/z: 1
== 1
>> a/y/z
== 8
>>
I hope that next release of REBOL will contain 'EXTEND function for adding
values into objects as Carl said some time ago.
Also something like make/deep will be useful...but this is stil repeated and
very old topic ;-)
Another feature what I'm missing when working is DOing some code in
specified context since Rebol's current DO does the code always in global
context. Maybe something like "do in a [x: 10]" should be useful...
Regards,
Cyphre