[REBOL] Re: blocks in and out function !
From: greggirwin:mindspring at: 8-Jan-2002 13:13
Hi Olivier,
<< I solved that problem by replacing the line "append/only g []" by
append/only g make block! []
. With that modification It works !
Could anyone give me an explaination ? Why the second code
do not behave like the first one ? >>
The empty blocks you are appending are referencing the *same* empty block.
REBOL words and values don't work exactly like variables in many other
languages. If you want a word to reference a unique, unshared, value, you
can use COPY to make a copy of an empty string or block. E.g.
addNode: make function! [g n][
append g n
append/only g copy []
]
Here's a simple example. 'a and 'b both reference the same empty block, so
when I modify 'a, the value referenced by 'b is also seen to change.
>> a: b: []
== []
>> append a 1
== [1]
>> b
== [1]
If I give each of them a copy of an empty block, they are not referencing
the same value anymore:
>> a: copy []
== []
>> b: copy []
== []
>> append a 1
== [1]
>> b
== []
Hope that helps!
--Gregg