[TYPES] what is "lexical" about "lexical scoping"?

Florian Weimer fw at deneb.enyo.de
Fri Aug 7 14:23:24 EDT 2020


* Stefan Monnier:

>> 2. "of or relating to a lexicon or to lexicography"
>>
>> That is the meaning I would associate with the phrase "lexical
>> scoping". As I understand lexical scoping, a scope is a dictionary or
>> lexicon, basically a map from identifiers of the concrete syntax to
>> binding sites of the abstract syntax. This dictionary is updated
>> during parsing. Perhaps "lexical" refers to the fact that the meaning
>> of the identifier is looked up in this (static) lexicon, as opposed to
>> determined dynamically at runtime?
>
> I don't really buy that explanation: the implementation of dynamic
> scoping also uses a "dictionary" where variables are looked up.
> The rules for which dictionary to use when is just a bit different from
> those of static scoping, but the lookup of variables in a lexicon is
> common to both scoping rules.

I think there is an implementation strategy where dynamic scope has
just a single, global environment, and shadowing of bindings is
implemented by explicit saving and restoring of symbol values.  One
could argue that the saved values formed a dictionary of some sort,
but it was not actually used for lookups, so that would be a stretch.

With that in mind, maybe scopes were called lexical because they have
lexicons associated with them, at least in a much more obvious way?


More information about the Types-list mailing list