2011-03-08 49 views
3

我對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 
+0

非常感謝!我以前嘗試過很多很接近但不夠近的東西。例如,我嘗試了x:print,然後x「hello world」,不知道:print。 – ultranewb 2011-03-08 18:06:10

+0

您能否提供涵蓋這些類型問題的文檔?我正在閱讀我在網上找到的「標準」文檔,但它只是涵蓋了「正常」的東西,如語言語法。 – ultranewb 2011-03-08 18:07:28

+0

REBOL3指南是一個開始的好地方,例如,請參閱此處的特殊符號:http://www.rebol.com/r3/docs/guide/code-words.html – Sunanda 2011-03-08 18:19:42