You're viewing version 1.2.0 of gensym. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

gensym

clojure.core

  • (gensym)
  • (gensym prefix-string)
Returns a new symbol with a unique name. If a prefix string is
supplied, the name is prefix# where # is some unique number. If
prefix is not supplied, the prefix is 'G__'.

3 Examples top

  • user=> (gensym "foo")
    foo2020
    
    user=> (gensym "foo")
    foo2027
    
    user=> (gensym "foo")
    ;; ...
    
  • user=> (gensym)
    G__2034
    
    user=> (let [my-unique-sym (gensym)]
             my-unique-sym)
    G__2075
    
  • ;; syntax-reader uses gensym for non-namespace-qualified symbols ending with '#'
    ;; http://clojure.org/reader
    
    user=> `(name0#)       ; gensym, form is useful in defmacro
    (name0__1206__auto__)
    
    user=> `(user/name1#)  ; no gensym, namespace-qualified
    (user/name1#)
    
    user=> `(:key0#)       ; no gensym, keyword
    (:key0#)
    
    user=> `(::key1#)      ; no gensym, keyword
    (:user/key1#)
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:483 top

(defn gensym
  "Returns a new symbol with a unique name. If a prefix string is
  supplied, the name is prefix# where # is some unique number. If
  prefix is not supplied, the prefix is 'G__'."
  {:added "1.0"}
  ([] (gensym "G__"))
  ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID))))))))
Vars in clojure.core/gensym: defn intern str
Used in 3 other vars deriv-fn* contract mapref-tree-model

Comments top

No comments for gensym. Log in to add a comment.