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: petr:krenzelok:trz:cz at: 28-Jan-2001 5:53

----- Original Message ----- From: <[rebol--mascari--org]> To: <[rebol-list--rebol--com]> Sent: Sunday, January 28, 2001 5:22 AM Subject: [REBOL] Scope? Any advice would be appreciated.
> 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:
Hi :-) I am not sure I am the one to answer context specific issues, but will try to :-)
> (1) the local variable "b" will be explicity set to [ 0 0 0 ]
right
> (2) the third element of "b" will be incremented by one, thus resulting
in
> [ 0 0 1 ]
right
> (3) because "b" is declared local, it should not be accessable outside of > the function
right
> (4) "b" will be destroyed when the function exits
not sure, the concet is called indefinite extent? Maybe it doesn't seem logical to you, but once you defined function, it is still alive (defined) and so reference to your block 'b exists ... The easiest solution is to use b: copy [0 0 0] as a declaration and Rebol will give you fresh copy of data you need, not those already referenced by local word 'b, which lives inside the context of the function ...
> 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).
I don't think 'b is static - it should be really local to your function....
> 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 > >>
And the result matches exactly to what I said above .... Hope-that-helps Cheers, -pekr-