[REBOL] Passing arguments to a function in another script
From: warren:howsoft at: 7-Feb-2008 13:48
Hi All,
Here is a script called arithfunc.r:
Rebol[]
sum: func [arg1 arg2] [
addem: arg1 + arg2
alert to-string addem
]
------------------------------------
In the same folder, I can successfully call the above function from
another script and pass its arguments as follows:
Rebol[]
mylay: layout[
button [do %arithfunc.r sum arg1: 3 arg2: 2]
]
view mylay
------------------------------------
Using the above, the Alert in the function correctly reports the result "5".
However, I would like to set the arguments above to variables rather
than citing the literals "3" and "2" as I have done above. The
following, for example, DOES NOT WORK:
Rebol[]
mylay: layout[
firstvar: 3
secondvar: 2
button [do %arithfunc.r sum firstvar secondvar]
]
view mylay
------------------------------------
Nor does this, or anything else I have tried:
Rebol[]
mylay: layout[
firstvar: 3
secondvar: 2
button [do %arithfunc.r sum arg1: firstvar arg2: secondvar]
]
view mylay
------------------------------------
All the above demonstrates a wonderful noob confusion, how typical I
don't know. I am obviously missing something!
Even in the version that works (using literals and not variables to pass
the arguments), I am not clear about why I need to say:-
button [do %arithfunc.r sum arg1: 3 arg2: 2]
- and NOT:
button [do %arithfunc.r sum 3 2]
Can anyone show me how to pass the arguments to the function in the
other script with the use of variables?
Thanks.
Bob