REBOL 元编程问题

发布于 2024-10-21 00:56:58 字数 292 浏览 1 评论 0原文

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

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

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

我尝试了很多不同的方法来在 REBOL 中执行类似的操作,但无法获得完全相同的效果。有人可以提供几种不同的方法来做到这一点(如果可能的话)?

谢谢。

I'm very new to REBOL (i.e. yesterday).

I am using the term "metaprogramming" here, but I'm not sure if it is accurate. At any rate, I'm trying to understand how REBOL can execute words. To give an example, here is some code in TCL:

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

I've tried many different ways to do something similar in REBOL, but can't get quite the same effect. Can someone offer a few different ways to do it (if possible)?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2024-10-28 00:56:58

这里有几个方法:

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

Here's a few 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文