Next: , Previous: , Up: Modules   [Contents][Index]

5.12.6 Modules and Special Variables

As described earlier, defvar creates dynamically scoped variables, or special variables. (see Defining Variables.) They do not fit well with the lexically scoped module system described here.

This means special variable definition must avoid clashing of name with those declared in other modules. The usual convention is to prefix the variable name with a unique string derived from the module name.

In fact, it is often advisable to avoid using special variables as much as possible. An alternative is to use fluid variable objects. These use first class Lisp objects to represent anonymous dynamically scoped variables. Since they are just Lisp objects, they may be stored in lexically scoped variables—this gives the benefits of both lexical (i.e. encapsulation) and dynamic scoping. See Fluid Variables.