[REBOL] Re: Confusion on when a block gets evaluated
From: lmecir::mbox::vol::cz at: 6-Mar-2006 8:33
Gregg Irwin napsal(a):
>Hi Jeff,
>
>First, you're jumping into deeper water that most newbies, so it's
>expected that you'll hit some confusing twists and turns (wait until
>you have a local series value in a function! :). It should all make
>sense before long and, hopefully, whatever I do to confuse you further
>will be addressed by somebody else. :)
>
>>>>test: [ repeat i 9 [ prin i ] ]
>>>>
>>>>
>JM> == [ repeat i 9 [ prin i ] ]
>
>The main thing to note about this snippet is that REPEAT will return
>the last value evaluated in the body block. In this case, that value
>is a block containing the result of the PRIN function, which is an
>unset! value.
>
>>>>do test
>>>>
>>>>
>JM> 123456789
>
>Notice that there's no "==" since the result of DOing the block was
>unset. Try REDUCE to see the result:
>
>>>reduce test
>>>
>>>
>123456789== [unset]
>
>or try this:
>
>>>print mold do test
>>>
>>>
>123456789** Script Error: mold is missing its value argument
>** Near: print mold do test
>
or this:
type? do test ; == unset!
>Now, you can see that DOing the test returns a single unset value,
>which PRINT can't consume (it's not a real value...until Ladislav
>jumps in to explain that it is, sort of, sometimes, but maybe it
>shouldn't be, because it's confusing ;).
>
LOL
...
maybe a short explanation will suffice:
reduce [1 + 2 3 + 4] ; == [3 7]
form [1 + 2 3 + 4] ; == "1 + 2 3 + 4"
form reduce [1 + 2 3 + 4] ; == "3 7"
You should be aware of the fact, that Print reduces a block it obtains.
You will find out, that there is a couple of functions in Rebol that
reduce their block argument in addition to Print and Join. (e.g. Repend,
c.f. source join)
-L