ToC DocOverview CGDoc RelNotes Index PermutedIndex
Allegro CL
Home Previous Up Next Table of Contents Index
  ANSI Common Lisp   10 Symbols   10.2 Dictionary of Symbols

10.2.7 gensym Function

Syntax:
gensym &optional x    new-symbol

Arguments and Values:
x - a string or a non-negative integer. Complicated defaulting behavior; see below.

new-symbol - a fresh, uninterned symbol.

Description:
Creates and returns a fresh, uninterned symbol, as if by calling make-symbol. (The only difference between gensym and make-symbol is in how the new-symbol's name is determined.)

The name of the new-symbol is the concatenation of a prefix, which defaults to "G", and a suffix, which is the decimal representation of a number that defaults to the value of *gensym-counter*.

If x is supplied, and is a string, then that string is used as a prefix instead of "G" for this call to gensym only.

If x is supplied, and is an integer, then that integer, instead of the value of *gensym-counter*, is used as the suffix for this call to gensym only.

If and only if no explicit suffix is supplied, *gensym-counter* is incremented after it is used.

Examples:
 (setq sym1 (gensym))  #:G3142
 (symbol-package sym1)   NIL
 (setq sym2 (gensym 100))  #:G100
 (setq sym3 (gensym 100))  #:G100
 (eq sym2 sym3)  false
 (find-symbol "G100")   NIL, NIL
 (gensym "T")  #:T3143
 (gensym)  #:G3144

Side Effects:
Might increment *gensym-counter*.

Affected By:
*gensym-counter*

Exceptional Situations:
Should signal an error of type type-error if x is not a string or a non-negative integer.

See Also:
gentemp, *gensym-counter*

Notes:
The ability to pass a numeric argument to gensym has been deprecated; explicitly binding *gensym-counter* is now stylistically preferred. (The somewhat baroque conventions for the optional argument are historical in nature, and supported primarily for compatibility with older dialects of Lisp. In modern code, it is recommended that the only kind of argument used be a string prefix. In general, though, to obtain more flexible control of the new-symbol's name, consider using make-symbol instead.)

Allegro CL Implementation Details:
None.

Home Previous Up Next Table of Contents Index
© Franz Inc. 1998-2015 - File last updated 03-23-2015