Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Scope? Any advice would be appreciated.

From: g:santilli:tiscalinet:it at: 28-Jan-2001 11:32

Hello [rebol--mascari--org]! On 28-Gen-01, you wrote: r> I stumbled across something tonight that appears to me to be a r> rather another nasty paradigm shift that I have to make (or r> perhaps its a bug). You will be enlightened if you look at the source of your function.
>> source lcdoesnt
lcdoesnt: func [/local b][ b: [0 0 0] print "The following line should ALWAYS be: 0 0 0 " print b b/3: b/3 + 1 print "The follwing line should ALWAYS be: 0 0 1 " print b print "......................." ]
>> lcdoesnt
The following line should ALWAYS be: 0 0 0 0 0 0 The follwing line should ALWAYS be: 0 0 1 0 0 1 .......................
>> source lcdoesnt
lcdoesnt: func [/local b][ b: [0 0 1] print "The following line should ALWAYS be: 0 0 0 " print b b/3: b/3 + 1 print "The follwing line should ALWAYS be: 0 0 1 " print b print "......................." ] All this is because you are still thinking in terms of variables, but REBOL does not have variables. REBOL has values only, and your 'b is a value of type WORD!. Words are able to refer to ONE other value (that is said to be its meaning). (Blocks are able to refer to MANY other values.) In the code above, you are changing the meaning of 'b, not 'b itself; 'b is "local" (actually, the association between 'b and its meaning is "local"), but the value it refers to is that very block above, not something that gets created and destroyed for every function call. To create a fresh block for each call, use: b: copy [0 0 0] or: b: make block! [0 0 0] Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/