[REBOL] Re: Scope? Any advice would be appreciated.
From: rebol:mascari at: 28-Jan-2001 10:47
Thanks to all that replied!
Everything somewhat makes sense. Everything is just an "object" that
maintains itself once declared. And code appears to be self-modifying.
Ok.
However, I have a follow-up question. The following routine *does* work:
lcWorks: func [ /local b ]
[
b: 0
print "The following line s/b 0"
print b
b: b + 1
print "The follwing line s/b 1"
print b
]
It doesn't need to use "copy" to make it work. I guess this issue just
boils down to assignment techniques.
Why do I have to use different assignment techniques? That is, in the
above example, a straightforward assignment of 0 to b works as one would
expect. However, the same concept applied to a block, b: [ 0 0 0 ] as in
the earlier example, does not work. Instead I have to make a copy of [ 0 0
0 ] - b: copy [ 0 0 0 ].
I am not clear as to why I would need to make a copy - why wouldn't the b:
[ 0 0 0 ] just blow away the current contents, even if the function and its
properties are maintained between calls? Similarly, in one of the previous
answers from Gabriele, he showed what appears to me to be behavior of self
modifying code. However, I still don't understand why using "copy" forces
the code to update, whereas the normal assignment operator does not.
Lastly, since the code appears to be self-modifying, and behavior of
assignments change depdending upon whether it is the first call or a
subsequent one, I am curious as to what advantages this has vs the
confusion that it will cause people coming from other programming
environments.
Thanks again,
Victor Mascari