< Previous | Contents | Next >

Global Variables

Once defined, global variables remain until Lisp is reloaded. Avoid using global

variables if at all possible! One specific problem arises when programs use the function

GENSYM. In program development, many atoms are created that may no longer be useful. Hints:

• Use

(DELDEF atomname ’PROP)

to delete property lists, and

(DELDEF atomname ’VARS)

to have the atom act like it is not defined.

These not only remove the definition from memory, but also change the appropriate fileCOMS that the deleted object was associated with so that the file package will not attempt to save the object (function, variable, record definition, and so forth) the next time the file is made. J ust doing something like

(SETQ (arg atomname) ’NOBIND)

looks like it will have the same effect as the second DELDEF above, but the SETQ does not update the file package.

• If you are generating atom names with GENSYM , try to keep a list of the atom names that are no longer needed. Reuse these atom names, before generating new ones.

There is a (fairly large) maximum to the number of atoms you can have, but things slow down considerably when you create lots of atoms.

• When possible, use a data structure such as a list or an array, instead of many

individual atoms. Such a structure has only one pointer to it. Once this pointer is

removed, the whole structure will be garbage-collected and space will be reclaimed.