user310291
user310291

Reputation: 38180

How can I change a global variable that have the same name as a local variable in Rebol or Red?

I cannot change the value of global variable a within f because it has the same name as a local variable: when function returns, a is still 1 instead of 12.

a: 1
f: func[a][set 'a a]
>> f 12
== 12
>> a
== 1

How can I refer to global variable a ? Isn't set supposed to only refer to global variable ? Am I obliged to change my local variable name to do so or is there a way to keep both name ?

Upvotes: 0

Views: 176

Answers (1)

DocKimbel
DocKimbel

Reputation: 3199

Use system/words/ path prefix to force read or write access to a word in global context:

>> a: 1
>> f: func[a][system/words/a: a]
== func [a][system/words/a: a]
>> f 12
== 12
>> a
== 12

Upvotes: 3

Related Questions