symbol

clojure.core

  • (symbol name)
  • (symbol ns name)
Returns a Symbol with the given namespace and name.

2 Examples top

  • ;; Returns a symbol with the given namespace and name.
    ;;
    ;; (symbol name): name can be a string or a symbol.
    ;;
    ;; (symbol ns name): ns and name must both be strings.
    ;;
    ;; A symbol string begins with a non-numeric character and can contain
    ;; alphanumeric characters and *, +, !, -, _, and ?.  (see
    ;; http://clojure.org/reader for details).
    ;;
    ;; symbol does not validate input strings for ns and name, and may return
    ;; improper symbols with undefined behavior for non-conformant ns and
    ;; name.
    
    user=> (symbol 'foo)
    foo
    
    user=> (symbol "foo")
    foo
    
    user=> (symbol "clojure.core" "foo")
    clojure.core/foo
    
  • ;; some gotchas to be aware of:
    
    user=> (symbol "user" 'abc)
    ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String  clojure.core/symbol (core.clj:523)
    user=> (symbol *ns* "abc")
    ClassCastException clojure.lang.Namespace cannot be cast to java.lang.String  clojure.core/symbol (core.clj:523)
    user=> (symbol 'user "abc")
    ClassCastException clojure.lang.Symbol cannot be cast to java.lang.String  clojure.core/symbol (core.clj:523)
    
    
    ;; Warning - the following generated symbols are non-conformant and may wreak
    ;; serious havoc in the near/far future when least expected...
    
    user=> (symbol "abc def")
    abc def
    user=> (symbol "123def")
    123def
    user=> (symbol "/123/def/ghi")
    /123/def/ghi
    user=> (symbol "/abc/def/ghi")
    /abc/def/ghi
    
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:517 top

(defn symbol
  "Returns a Symbol with the given namespace and name."
  {:tag clojure.lang.Symbol
   :added "1.0"
   :static true}
  ([name] (if (symbol? name) name (clojure.lang.Symbol/intern name)))
  ([ns name] (clojure.lang.Symbol/intern ns name)))
Vars in clojure.core/symbol:
Used in 0 other vars

Comments top

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