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

[REBOL] Scope? Any advice would be appreciated.

From: rebol::mascari::org at: 27-Jan-2001 23:22

I stumbled across something tonight that appears to me to be a rather another nasty paradigm shift that I have to make (or perhaps its a bug). I have reduced the problem and wrote this function to illustrate it (I named it lcDoesnt because it doesn'd do what I expect): 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 "......................." ] My expectations are the following: (1) the local variable "b" will be explicity set to [ 0 0 0 ] (2) the third element of "b" will be incremented by one, thus resulting in [ 0 0 1 ] (3) because "b" is declared local, it should not be accessable outside of the function (4) "b" will be destroyed when the function exits This pattern should repeat indefinitely as "b" is being explicity set within the function. However, this is *not* the case. Only item #3 holds. The problem is that "b" is somehow static, and so static, that even when the function explicitly *assigns* its value, that the explicit assignment is ignored in subsequent calls to the function (but not the first). Here is the output from my Rebol/View console (as you can see, the third element is being incremented, and is acting like a counter). Also note that "b" is indeed not accessable to the global area as it should be, but it must still exist somewhere else.
>> 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 .......................
>> lcdoesnt
The following line should ALWAYS be: 0 0 0 0 0 1 The follwing line should ALWAYS be: 0 0 1 0 0 2 .......................
>> b
** Script Error: b has no value. ** Where: b
>>
Any advice would be appreciated. Thanks, Victor Mascari