gensym returns a unique Clojure symbol, mainly helping macro authors avoid accidental symbol capture when syntax-quote does not provide enough automatic generation. section 4.0 section 4.4
Its contract is small:
- Call (gensym) to use the default G__ prefix. section 4.4
- Call (gensym "prefix") to choose a prefix string. section 4.4
- Receive a symbol whose name combines the prefix with a number unique in the current Java instance. section 4.4
Generating names for transformed expressions
(gensym) ; => G__14 (gensym "my-prefix") ; => my-prefix17 A logic-expression transformation can bind a fresh local instead of reusing an existing variable: (pull-quantifier '(OR (EXIST x (Q x)) (P x))) ;; => (EXIST local2747 (OR (P x) (Q local2747))) The generated local prevents the moved quantifier from capturing the wrong x. section 4.4 section 4.4
(gensym) ; #1 ;; G__14 (gensym "my-prefix") ; #2 ;; my-prefix17
Inspect representative default- and custom-prefix results from gensym. section 4.4
