tags:

views:

41

answers:

1

I have experimented with this:

>> code-block: copy []
== []
>> append code-block [func[][print "a"] ]
== [func [] [print "a"]]
>> do do code-block
a
>>

Is there a way to avoid to do "do" twice :)

+1  A: 

What you have put into code-block is not the function, but the source of the function, hence the need to do it once to make a function, then do it again as a function.

You can see that like this:

length? code-block
== 3

To just put the function in code-block, can do this:

code-block: copy []
append code-block func[][print "a"]    ;; no block around the FUNC

Or this:

code-block: copy []
append code-block reduce [func[][print "a"] ]  ;; use REDUCE to evaluate the block

Either way, what is in code-block is now just the function:

length? code-block
== 1
type? first code-block
== function!
do code-block     ;; what you asked for!
a
Sunanda
Doesn't reduce play the same role as the second do in fact ?
Rebol Tutorial
In effect, yes. But it happens only once: when the block is created; not every time when the code in the block is executed. So it should be faster overall.
Sunanda