Hi Carl,
You've tripped over a usage which is normally comes up when people define
functions.
In the second example, each time through the loop a new block value is
created and block2 is set to this new value. So your insert modifies a
different block each time.
In the first example a block value is created once at some point when the
interpreter goes to execute your loop, then each time through the loop the
word block1 is set to this same value. Hence you are modifying the same
block (in memory).
Note: In my explanation I've made reference to memory and the interpreter. I
don't know if this is how it works for sure, but it should give you the
idea.
For more messages on the same theme see:
http://www.codeconscious.com/rebol/tips-and-techniques.html#Wordsarenotvaria
bles1
Brett.
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 18, 2000 7:13 PM
Subject: [REBOL] Block Creation
> Here's a block query...
>
> >> block1: []
> == []
>
> >> block2: to-block ""
> == []
>
> The above would appear to have created identical blocks, but as the
> following little script shows they're not the same...
>
> rebol []
> for test1 1 5 1 [
> block1: []
> insert block1 "text1"
> ]
> prin "block1: " print block1
> for test2 1 5 1 [
> block2: to-block ""
> insert block2 "text2"
> ]
> prin "block2: " print block2
>
> The output from this is...
>
> block1: text1 text1 text1 text1 text1
> block2: text2
>
> I'm assuming this is normal REBOL behaviour and not a bug, (and I
> know...
>
> block1: [] clear block1
>
> would've given the same results as with to-block), but what's the
> point of the difference?
>
> Carl Read.
>