REBOL Metaprogramming Issues

I am very new to REBOL (i.e. yesterday).

I use the term “metaprogramming” here, but I'm not sure how accurate it is. Anyway, I'm trying to figure out how REBOL can execute words. To give an example, here is the code in TCL:

> # puts is the print command
> set x puts
> $ x "hello world"
hello world

I tried many different ways to do something similar in REBOL, but cannot get the same effect. Can someone suggest a few different ways to do this (if possible)?

Thank.

+3
source share
1 answer

Here are some ways:

x: :print           ;; assign 'x to 'print
x "hello world"     ;; and execute it
hello world

blk: copy []               ;; create a block
append blk :print          ;; put 'print in it
do [blk/1 "hello world"]   ;; execute first entry in the block (which is 'print)
hello world

x: 'print                  ;; assign 'x to the value 'print
do x "hello world"         ;; execute the value contained in 'x (ie 'print)
hello world

x: "print"                ;; assign x to the string "print"
do load x "hello world"   ;; execute the value you get from evaluating 'x
hello world
+7
source

All Articles