Tim,

you had this something like this:

command1: [print "doing command 1"]

do rejoin ["command" command]

try this:

do to word! rejoin ["command" command]

or this:

do do rejoin ["command" command]


your earlier equivalent was basically the same as this:
do "command1"

which is apparently not the same as this
do command1

do "command1"
is just enough to fetch the value of command 1, which is a block,
but that block is not required to be interpreted immediately, you see.

By turning "command1" into a word first, then the automatic parameter fetching
of a word
will grab the block and pass it to do.  So in that case, do never even sees the
actual
command1 word, it just sees it's reduced value, the block, and executes that.

If command1 had been defined as a function instead of as a block, then the
automatic running of it would have been seen even with the way you were doing
it.

It's sometimes hard to remember when you are working with Rebol
that all this parameter evaluation is going on automatically.

For instance, print doesn't just print the value, it evaluates everything first,
and then
prints that.  You have to use probe and "get" into the "words" a bit to really
see
more behind the scenes.

Basically, if command1 had been a function instead of just a block,
you would have succeeded.

Check this out:

>> do "print {hello}"
hello

this works because print is itself a function, not a block

>> do "[print {hello}]"
== [print "hello"]

this doesnt work by itself because a block is just a block,
which is returned as the result of doing the string.

notice that you would have gotten exactly the same result
by just typing the block at the prompt:

>> [print "hello"]
== [print "hello"]


but these work:

>> do do "[print {hello}]"
hello

>>do "do [print {hello}]"
hello

Even when you type stuff in at the command prompt, rebol is "do"-ing that,
so it gets reduced and evaluated.

And bizarrely enough for the beginner's perspective, one of the main jobs
of brackets is to suppress evaluation, e.g. here's the code, but to be run
LATER,
and not evaluated immediately.  In your original example, the block value
of command1 or command2 is fetched, and probably even bound and
ready to go, but you didn't tell it to do that resulting value...

notice that had you just typed this, it would amount to the same thing:

>> command1
== [print "Doing Command 1"]

See, it's fetched, but not executed.  But it is ready to rock.  Just do that.

------------

Rebol, is of course nearly a human language, and therefore easy to understand.
;-)

You have to admire the flexibility here, though.  You just invented code on the
fly.
Beats the heck out of most languages right there.  The only others that can
really
do this are things like Lisp and Scheme and Smalltalk, too, I believe.
Java won't really do it, will it?  Anybody?

-galt



Reply via email to