On 12/27/1999 at 4:08 PM [EMAIL PROTECTED] wrote:

{{In the standard implementation model, Pascal local variables are
allocated on the stack upon entry to a procedure, and deallocated
upon exit from the procedure.  There's no way to make a local
var from one procedure refer to the content of a local var from a
different procedure (except via pointers, and then one gets into
the danger of the "dangling reference" problem).  

OTOH, by using 'bind it IS possible to make the word/value
association that exists within one context available to another.
That's a very large difference, IMHO.}}

Well, allocating locals on the stack is certainly one way to do it, but
the language itself only requires the behavior. And most
implementations, I think, clearly defined whether a local variable was
initialized or not. In the Borland implementation, the answer was not,
since they included a keyword ABSOLUTE which let you define two
variables names at the same memory location. Meanwhile, I also believe
C has a static keyword that preserves local variables between function
calls, which implies those locals at least are stored outside the
stack. "Nothing new under the sun."

But, back on thread, since words can be bound as functions as well as
variables, I imagine the implementation model is probably a tree
structure, such as is used to scope nested subroutines. Unlike many
other languages, REBOL needs to store "variables" and "functions" in
the same space, since a word can be one and then the other, and all
words can be evaluated, whether they store a scalar  or a script. I
can't just put a Pascal variable on a line by itself and expect the
compiler to do something with it!

I also wonder if some of the behavior we see in local variables
retaining values across function calls is by design or happenstance.
The documentation doesn't seem to specify whether local variables are
initialized. At the first evaluation, they seem to start out as none,
but then ...dunno. 

-T.

Incidentally,. I'm really enjoying your posts, Joel. 



Reply via email to