Previous: , Up: Symbols   [Contents][Index]

7.2 Creating Symbols

These functions create unique symbols, typically for use as temporary variables.

Function: cl-gensym &optional x

This function creates a new, uninterned symbol (using make-symbol) with a unique name. (The name of an uninterned symbol is relevant only if the symbol is printed.) By default, the name is generated from an increasing sequence of numbers, ‘G1000’, ‘G1001’, ‘G1002’, etc. If the optional argument x is a string, that string is used as a prefix instead of ‘G’. Uninterned symbols are used in macro expansions for temporary variables, to ensure that their names will not conflict with “real” variables in the user’s code.

(Internally, the variable cl--gensym-counter holds the counter used to generate names. It is incremented after each use. In Common Lisp this is initialized with 0, but this package initializes it with a random time-dependent value to avoid trouble when two files that each used cl-gensym in their compilation are loaded together. Uninterned symbols become interned when the compiler writes them out to a file and the Emacs loader loads them, so their names have to be treated a bit more carefully than in Common Lisp where uninterned symbols remain uninterned after loading.)

Function: cl-gentemp &optional x

This function is like cl-gensym, except that it produces a new interned symbol. If the symbol that is generated already exists, the function keeps incrementing the counter and trying again until a new symbol is generated.

This package automatically creates all keywords that are called for by &key argument specifiers, and discourages the use of keywords as data unrelated to keyword arguments, so the related function defkeyword (to create self-quoting keyword symbols) is not provided.

Previous: , Up: Symbols   [Contents][Index]