Setting global from within a function.
[1/3] from: terry::depotcity::com at: 8-Feb-2001 10:58
Hello all.
Another question.
How do you set a global word from a func word eg;
n: [1 2]
the-funk: func [the-input][
if (first the-input) = 2 [
{Set the global value of the-input, in this case N, to som
ething? eg: 42}
]
]
the-funk n
>> n
== 42
Thanks.
Terry Brownell
[2/3] from: ryanc:iesco-dms at: 8-Feb-2001 11:34
You probably had the right idea the first time... watch close
>> n: [1 2]
== [1 2]
>> the-funk: func [the-input] [
[ if (first the-input) = 2 [ n: 42 ]
[ ]
>> the-funk n
== none
>> n
== [1 2]
>> ;correct answer, nothing happened
>> the-funk head reverse n
== 42
>> n
== 42
>>;correct answer too.
If you have'nt got it yet, you were looking for 2, which was at the
second position (second n). By using the head reverse instructions I
actually passed [2 1] to your function causing n to be set.
The REBOL part is easy, not making those damn logic errors is the
difficult part!
--Ryan
Terry Brownell wrote:
> Hello all.
> Another question.
<<quoted lines omitted: 15>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein
[3/3] from: lmecir:mbox:vol:cz at: 8-Feb-2001 20:34
Hi Terry,
you probably meant something like this:
the-funk: func [the-input][
if (first get the-input) = 2 [
set the-input 42
]
]
Regards
Ladislav
n: [2 1] ; == [2 1]
the-funk 'n ; == 42
n ; == 42
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted