【问题标题】:REBOL metaprogramming questionsREBOL 元编程问题
【发布时间】:2011-03-08 16:26:21
【问题描述】:

我对 REBOL 很陌生(即昨天)。

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

> # puts 是打印命令 > 设置 x 看跌期权 > $x“你好世界” 你好世界

我尝试了许多不同的方法来在 REBOL 中做类似的事情,但无法获得完全相同的效果。有人可以提供几种不同的方法(如果可能的话)吗?

谢谢。

【问题讨论】:

    标签: metaprogramming rebol


    【解决方案1】:

    这里有几种方法:

    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
    

    【讨论】:

    • 非常感谢!我以前尝试过很多很接近但不够接近的东西。例如我尝试了 x: print 然后 x "hello world",不知道 :print。
    • 您能否推荐涵盖这些类型问题的文档?我正在阅读我在网上找到的“标准”文档,但它只涵盖了“正常”的东西,比如语言语法。
    • REBOL3 指南是一个很好的起点,例如,请参阅此处的单词特殊符号:rebol.com/r3/docs/guide/code-words.html
    • 本文档适用于 R2 但与 R3 非常相似,我建议您也阅读此文档:rebol.com/docs/core23/rebolcore.html
    • 谢谢,这真是太有见地了。
    猜你喜欢
    • 1970-01-01
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多