User Tools

Function GENSYM


  • gensym &optional xnew-symbol

Arguments and Values


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.


(defparameter *sym1* (gensym))


(symbol-package *sym1*)


(defparameter *sym2* (gensym 100))


(defparameter *sym3* (gensym 100))


(eq *sym2* *sym3*)


(find-symbol "G100")


(gensym "T")




Side Effects

Might increment *gensym-counter*.

Affected By

Exceptional Situations

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

See Also


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.)