REBOL元编程问题

ult*_*ewb 3 metaprogramming rebol

我对REBOL很新(即昨天).

我在这里使用"元编程"一词,但我不确定它是否准确.无论如何,我试图了解REBOL如何执行单词.举个例子,这里是TCL中的一些代码:

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

我已尝试过许多不同的方法在REBOL中做类似的事情,但不能达到完全相同的效果.有人可以提供几种不同的方法(如果可能)吗?

谢谢.

小智 7

这有几种方法:

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
Run Code Online (Sandbox Code Playgroud)