Passing by reference

Hi,

I have a quick question.  How can I pass a variable to a function by reference
(as opposed to by value) in Rebol?  I have tried fiddling with "to-set-word",
literal words, etc., but to no avail.  I am probably missing something
obvious.

As a quick example, how could I write, say, a function that incremented the
value of a variable.  Obviously this doesn't work:

inc: func [i] [i: i + 1]
j: 0
inc j

print j
>> 0

because it just increments the value passed in to inc.  How do I write inc so
that it takes a reference and modifies the thing it refers to, and how do I
then call the function (inc 'j or inc j)?

I also notice that:

a: 0              ; >> 0
b: 'a             ; >> a
to-set-word b     ; >> a:
to-set-word b 1   ; >> 1
a                 ; >> 0

so what is the point of to-set-word if I can then not use it to set the thing?
Do I need an extra block and a "do" or something like that?

I've been following the argument about conceptual models of the language,
etc., and I have to admit that it would help me too.  I only just found out
about the draft manual on the web site from posts on this list (I didn't
notice a link on the web site), so I shall mug up on that and see if it helps
my understanding of how Rebol handles these issues.

Thanks in advance for any help,

Richard

Reply via email to