Hi Carl,
Anton and Brett already pointed out the difference. I merely want to add
that in the first case
>> block-1: []
you are assigning the word block as a reference to a LITERAL block. At
each loop iteration the word block-1 is being assigned to that same
LITERAL block.
Case 2:
>> block-2: to-block ""
Better yet:
>> block-2: to-block []
Here to-block creates a new block PROGRAMMATICALLY at each iteration
using the LITERAL block [] as a prototype. The prototype block remains
empty. The values are inserted into the empty PROGRAMMATICALLY (or
DYNAMICALLY) created block, not into its LITERAL prototype.
So,
>> repeat i 3 [block-1: [] insert block-1 i]
is the programmatic equivalent of
>> block-1: [3 2 1]
whereas
>> repeat i 3 [ block-2: to-block [] insert block-2 i]
is the programmatic equivalent of
>> block-2: [1]
>> block-2: [2]
>> block-2: [3]
A combination of the two allows you to do something like this:
repeat i 3 [
block-2: to-block block-1: []
append block-1 i
repeat j 3 [
append block-2 j
]
]
Here we modify the literal prototype block in the outer loop, and then
modify the result ing programmatically created block in the second loop.
Hope this sheds a little more light on how to utilize the difference.
Elan
[EMAIL PROTECTED] wrote:
> 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.