I'm trying to put together a code generator and need to print a block (that contains some code for a target language) without it (i.e, the block) being evaluated. How should I go about doing this?
Edit 1 -- I understand that this could be easily accomplished if I were to embed the Ruby code as a string but since the Rebol parser doesn't seem to mind, I thought why not?
rebol []
x: [
[sym0 [(1..10).map{|n| puts n}]]
[sym1 [foo << [1, 2, 3]]]
]
print x/1/1 ;prints sym0
print x/1/2 ;fails as print tries to evaluate the block
Try MOLD. It generates a string from Rebol data:
Note that MOLD is not a perfect counterpart to LOAD. In the above case, you could LOAD that structure back out of the string...but some of the binding information is going to be lost in the general case.
Edit 1: Well what you are trying to do is pretty wacky. What you get from mold is:
It speaks to Rebol's curious nature that so many things are legal that other languages would generate syntax errors over. That's part of what makes it a nice adaptable English-like system for writing DSLs.
But... Rebol simply isn't Ruby. The lexical interpretation of symbols is totally different. That means you either have to do something Rubol-like to "shoehorn" Ruby code into Rebol's model as a kind of "Ruby DOM"... and then coerce it back out with a
ruby-mold
(which could be cool, I'm for it). Or you have to use a string.