[REBOL] Re: Why should I copy ?
From: dhsunanda:gma:il at: 24-Sep-2009 17:22
It's probably easier to see what is going on with my example, where the
equivalent code is a block in a function:
=====
f: func [
/local blk
][
blk: []
for n 1 3 1 [
append blk n
source f
]
]
f
f
f
=====
Watch the source of the 'f function as you run it....It keeps changing.
That's because
b: []
associates the word 'b with an empty block, []. Append value to 'b and
[] is not empty any more!
There is a lengthy discussion here:
http://www.rebol.org/ml-display-thread.r?m=rmlRDLB
***
Lesson: use COPY. it associates the word 'b with a fresh [] each time
=====
f: func [
/local blk
][
blk: COPY []
for n 1 3 1 [
append blk n
source f
]
]
f
f
f
=====
This behaviour can take a while to get used to ;)
Sunanda