[REBOL] Re: : [] in a function => was {Re: Re: to-char}
From: al:bri:xtra at: 14-Feb-2002 17:43
Jason wrote:
> This is what I still don't deeply get:
> Q: Why, at the console does someblock: [] create a fresh block, but within
a script function someblock: [] persists and needs to be remedied by copy
[], clear [] or make block! 123 statements?
When you type this at the console:
someblock: []
you're assigning the value of the word 'someblock to the next value
following, which happens to be a block!. When you type in the superficially
similar line at the console again:
someblock: []
Note that the "[]" is _another_ block value, not the same block. As can
be seen:
>> b: someblock: []
== []
>> append someblock "a"
== ["a"]
>> append someblock "b"
== ["a" "b"]
>> append someblock "c"
== ["a" "b" "c"]
>> someblock: []
== []
>> b
== ["a" "b" "c"]
Now 'b and 'someblock refer to different block! values.
Here's a function body:
>> Body: [
[ someblock: []
[ append someblock random 10
[ someblock
[ ]
== [
someblock: []
append someblock random 10
someblock
]
Now we 'do Body, much like a function, twice:
>> do Body
== [5]
>> probe Body
[
someblock: [5]
append someblock random 10
someblock
]
== [
someblock: [5]
append someblock random 10
someblock
]
>> do Body
== [5 2]
>> probe body
[
someblock: [5 2]
append someblock random 10
someblock
]
== [
someblock: [5 2]
append someblock random 10
someblock
]
And inspect the second value in the block! value refered to by 'Body:
>> probe pick Body 2
[5 2]
== [5 2]
I hope that helps!
Andrew Martin
ICQ: 26227169 http://valley.150m.com/