[REBOL] Confusion on when a block gets evaluated
From: massung::gmail::com at: 5-Mar-2006 23:38
I'm getting a tad bit confused on when REBOL decides to treat something as
code. If I open up the console and type a couple snippets of code, the
language doesn't quite work the way I expect it to (coming from Lisp). I'm
hoping some of the more experienced here can lend me a quick explanation...
:)
Here I'll show my little test in REBOL along with a Lispy counterpart to
show what I think should happen.
>> test: [ repeat i 9 [ prin i ] ]
== [ repeat i 9 [ prin i ] ]
Okay, now I have a word (test), which is bound to a list of data consisting
of words, an integer, and another list of words. Simple enough:
(setf test '(repeat i 9 (prin i))).
>> do test
123456789
Looks good. It treated the list as a block of code and executed it.
(eval test)
>> print test
123456789?unset?
Huh? Shouldn't it have just printed the list like the original assignment
return value?
(print test) -> (repeat i 9 (prin i))
I know that I can get the original list by doing:
>> get 'test ; or :test
== [ repeat i 9 [ prin i ] ]
But I just figured for the print statement, test would just be evaluated
(after all, test is just a list, evaluating the list would be an extra step,
which is what I assume is what DO does, but it seems that PRINT does it,
too)?
So, now assuming that maybe PRINT is a special case senario, I decided to
try another simple function: JOIN. I get the same "quirkyness" (well, quirky
being defined as "not what I expect :)"):
>> join "foo" test
123456789 == "foo?unset?"
>> join "foo" get 'test
123456789 == "foo?unset?"
>> join "foo" :test
123456789 == "foo?unset?"
>> join "foo" [test]
== "foorepeat i 10 prin i"
I would have expected the first to do what the last did. So, for now, I
gather that that words are evaluated (completely) before being passed on to
another function. So, to test that theory, here's my next statement:
foo: func [block] [
prin "**" do block print "**"
]
>> foo test
**123456789**
If the my hypothesis was correct, what I would have expected as output would
have been:
123456789**?unset?**
So, now I'm utterly confused. :)
Now, I'm sure there's just one tiny snippet of REB-know-how that I'm missing
(or a trivial step in the evaluation process that I'm not aware of) at the
moment that will make this all just "come together" for me. Consider me
waiting to be enlightened. :)
Thanks!
Jeff M.
--
massung-gmail.com