Macro WITH-UNIQUE-NAMES
Syntax:
with-unique-names ({var | (var prefix)}*) declaration* form* => result*
Arguments and Values:
var---a symbol; not evaluated.
prefix---a string designator; not evaluated. The default is var.
declaration---a declare expression; not evaluated.
form---a form.
results---the values returned by the forms.
Description:
Executes a series of forms with each var bound to a fresh, uninterned symbol. The uninterned symbol is created as if by a call to gensym with the string denoted by prefix---or, if prefix is not supplied, the string denoted by var---as argument.
The variable bindings created are lexical unless special declarations are specified. The forms are evaluated in order, and the values of all but the last are discarded (that is, the body is an implicit progn).Examples:
(with-unique-names (sym1) sym1) => #:SYM13142 (with-unique-names ((sym1 "SYM1-")) sym1) => #:SYM1-3143 (find-symbol "SYM1-3143") => NIL, NIL (with-unique-names ((sym #\Q)) sym) => #:Q3144 (with-unique-names ((sym1 :sym1-)) sym1) => #:SYM1-3145 (with-unique-names (sym1) (symbol-package sym1)) => NIL (with-unique-names (sym8) (eq sym8 sym8)) => T (with-unique-names (sym9) (set sym9 42) (symbol-value sym9)) => 42
Side Effects:
Might increment *gensym-counter* once for each var.
Affected by:
Exceptional Situations:
None.
See Also:
Notes:
This is an extension of the classic macro with-gensyms. In fact, cl-utilities also exports with-gensyms, and it can be used as usual. The exported with-gensyms is actually just an alias for with-unique-names which gives a warning at compile-time if the extensions of with-unique-names are used.
You are encouraged to use with-unique-names instead of with-gensyms because it is a little more flexible and because it tells what is going on rather than how it works. This is a somewhat controversial point, so go ahead and use whichever you like if you have an opinion on it. But if you're a newbie who honestly doesn't care, please use with-unique-names.