3

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.

ultranewb
  • 33
  • 2

1 Answers1

7

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
Sunanda
  • 1,555
  • 7
  • 9
  • Thanks very much! I previously tried many things which were close, but not close enough. For instance I tried x: print and then x "hello world", didn't know about :print. – ultranewb Mar 08 '11 at 18:06
  • Can you suggest documentation which covers these types of issues? I'm reading "standard" documentation which I find on the web, but it just covers "normal" stuff like language syntax. – ultranewb Mar 08 '11 at 18:07
  • The REBOL3 guide is a good place to start, see, for example, Special notations for words here: http://www.rebol.com/r3/docs/guide/code-words.html – Sunanda Mar 08 '11 at 18:19
  • This document is for R2 but it is very similar with R3, I recommend you to read this also: http://www.rebol.com/docs/core23/rebolcore.html – endo64 Mar 09 '11 at 08:04