A CLOS protocol for lexical environments
Robert I. Strandh, Irène Durand · Zenodo (CERN European Organization for Nuclear Research) · 2022
The concept of an environment is mentioned in many places in the Common Lisp standard, but the nature of the object is not specified. For the purpose of this paper, an environment is a mapping (or several such mappings when there is more than one namespace as is the case for Common Lisp) from names to meanings. In this paper, we propose a replacement for the environment protocol documented in the book ``Common Lisp the Language, second edition'' by Guy Steele. Rather than returning multiple values as the functions in that protocol do, the protocol suggested in this paper is designed so that functions return instances of standard classes. Accessor functions on those instances supply the information needed by a compiler or any other code walker application. The advantage of our approach is that a protocol based on generic functions and standard classes is easier to extend in backward-compatible ways than the previous protocol, so that implementations can define additional functionality on these objects. Furthermore, CLOS features such as auxiliary methods can be used on these objects, making it possible to extend or override functionality provided by the protocol, for implementation-specific purposes.