Re: global variables, no lexical address



Wolfram wrote...

I'm not quite sure I understand everything you say because I don't have the
book »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.

When an evaluator uses lexical addresses, is it acceptable/normal for the
environment representation to contain global variables?

Yes. The built-in functions and variables of the defined language have to
pre-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).

On further thought I might be wrong. Maybe the globals variables do have
lexical addresses. Is that right?

OK, maybe you were not talking about built-in functions after all. If you
don'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 current
lexical 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 into
addresses, 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


.



Relevant Pages

  • Re: why cannot assign to function call
    ... which is a reference to an object. ... /environment/; if the environment assigns a meaning to a name, ... the enclosing block, i.e., within the inner block, a few names are bound ... to new meanings, while all the other names retain whatever meaning they ...
    (comp.lang.python)
  • Outlook 2003 Object Library load failure
    ... test sites for over a year. ... started failing in my test environment with a runtime filenotfound error. ... Further research revielded that the Object Library reference for Outlook has ... a GAC reference instead of Copy Local True. ...
    (microsoft.public.outlook.program_vba)
  • Re: Referencing Figures With Labels Does Not Work
    ... \endenvironment. ... interested in floating objects. ... LaTeX FAQ: http://www.tex.ac.uk/faq ... To reference such figures for further referencing. ...
    (comp.text.tex)
  • Re: Restore a DTS Packaga Saved As Visual Basic File?
    ... opened the saved DTS Visual Basic file in the following environment: ... Attempted to add Reference to the project: [Microsoft DTSPackage Object Library] but got the following error message.. ...
    (microsoft.public.sqlserver.dts)
  • Re: global variables, no lexical address
    ... represent variable references in expressions. ... I mean the initial environment has ... Maybe the globals variables do ... replacing the variable name with something like (lexical-ref 5) you ...
    (comp.lang.scheme)