Re: global variables, no lexical address
- From: "Marlene Miller" <marlenemiller@xxxxxxxxxxxxxxxx>
- Date: Mon, 04 Sep 2006 19:24:35 GMT
Wolfram wrote...
I'm not quite sure I understand everything you say because I don't have thebook »Essentials of Programming Languages«, but I'll try anyway. If I
understand you correctly, you're trying to implement some sort of compiler
and one task is to replace references to variables with the address of the
variable, right?
Yes.
In this book, a lexical address is a depth and position describing the place
in the text of the variable declaration. The variable reference in the
abstract syntax tree is replaced with a depth and position. The environment
has only values, no variables. The lexical address is used to locate the
value in the environment.
The purpose of the evaluators in this book is, I assume, to
describe/understand the semantics of languages. If the purpose were to get
the value of an expression, we could use any coding mechanism. My question
is about the correct way to think about the semantics of the language.
environment representation to contain global variables?When an evaluator uses lexical addresses, is it acceptable/normal for the
Yes. The built-in functions and variables of the defined language have topre-exist in the initial global environment if they cannot be defined in the
language itself.
It concerns me that for variables declared by lambda and let expressions,
only the value of the binding is in the environment, whereas for predefined
variables (which have no declaration and hence no depth and position
relative to a variable reference), the whole binding - the identifier and
the value - must be in the environment (in order to lookup the predefined
variable).
lexical addresses. Is that right?On further thought I might be wrong. Maybe the globals variables do have
OK, maybe you were not talking about built-in functions after all. If youdon't want special treatment for references to global variables, you would
have to transform you programs like this:
I meant built-in (or predefined) variables. I used the wrong word - globals.
I don't want special treatment for predefined variables. But it occurred to
me, that is a mechanical issue not semantics.
I don't know what you mean by »increments the lexical address depth«,
In this book, depth is the scope nesting level from the variable reference
to the variable declaration. Since predefined variables do not have
declarations, they do not have depth. I suppose we could stretch the
definition of depth and say the depth of a variable reference to a prefined
variable is one more than the last enclosing scope. I am not sure whether
that is coding mechanics or semantics.
but the rest sounds correct. If a name isn't defined in the currentlexical environment, it could be a reference to a pre-existing
function/variable, or a global function/variable. So instead of replacing
the variable name with something like (lexical-ref 5) you would replace it
with (predefined-ref 3) or (global-ref 17).
Ah! This could be the answer I am looking for. Tag the values in the
environment. That might be better than pretending the predefined variables
have a lexical address. Thank you for the suggestion.
Now, back to addresses: all variables references can be transformed intoaddresses, i. e. indices into some vector. But depending on where the
variable »lives«, you have several different vectors, namely the current
lexical environment (this is the current stack frame), the vector of free
variables, maybe the vector of global variables, and the (global) vector of
pre-defined functions and variables. The vectors are allocated at different
times during program execution: The vector of pre-defined objects is
allocated before the program is started, as is the vector of global
variables. A new vector of free variables is allocated each time a function
is created, i. e. each time you encounter (lambda (...) ...). Lexical
environments are created each time a function is applied.
This is a little confusing to me because I don't see the notion of nested
scopes. I like EoPL. Maybe I need to read more about lexical addresses in
another book. Do you have any recommendations?
- - - - - - - - - -
Given that lexical addresses (depth and position) can replace variable
references, should we say a variable reference refers to a place in the text
where a value first appears (instead of saying a variable reference refers
to a value)?
Marlene
.
- Follow-Ups:
- Re: global variables, no lexical address
- From: int2k
- Re: global variables, no lexical address
- References:
- global variables, no lexical address
- From: Marlene Miller
- Re: global variables, no lexical address
- From: Marlene Miller
- Re: global variables, no lexical address
- From: int2k
- global variables, no lexical address
- Prev by Date: Re: Scheme and libraries -- piggyback on Java?
- Next by Date: Re: global variables, no lexical address
- Previous by thread: Re: global variables, no lexical address
- Next by thread: Re: global variables, no lexical address
- Index(es):
Relevant Pages
|