[EMAIL PROTECTED] wrote:
> REBOL []
>
> my-words: [ 'rebol "Blue" ( 7 * 2 ) ]
>
> loop 2 [ foreach word my-words [ print word] foreach word my-words [ probe word ]]
When the script is loaded, the ascii text is converted to a block
of REBOL values. The first value of the block here is the set-word
"my-words:", the second is the block "['rebol ...]" etc. Just
after loading, the block (that is, every word in it, recursively)
is bound to the global context (system/words). So "my-words:" is
bound to system/words, "'rebol" is bound to system/words, and so
on with "*", "loop", "foreach" etc.
When the block is executed, the block "['rebol ...]" is assigned
to "my-words" in the global context, because "my-words:" is bound
to the global context. "loop" is bound to the global context,
where it means the native function LOOP. So the block "[foreach
word ...]" is executed twice.
"foreach" is bound to the global context, so the native function
FOREACH is evaluated. It gets its arguments, "word", "my-words"
(wich is evaluated to the block it means) and "[print word]". It
creates a new context, containing only the word "word". The block
"[print word]" is then bound to that context: this process leaves
"print" untouched (that is, bound to system/words) because it is
not present in tha new context; "word", instead, is found in the
new context and therefore is bound to that. Then the function
FOREACH assigns the first value of the block "['rebol ...]" to the
word "word" in the new context and evaluates the block "[print
word]". Here "print" means the native function PRINT and "word"
means "'rebol", as explained above. Then FOREACH goes ahead to the
second value of the block (the string "Blue"), etc.
The same thing happens for the second "foreach", and so on.
HTH,
Gabriele.
--
Gabriele Santilli <[EMAIL PROTECTED]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/