• (defalias name orig)
  • (defalias name orig doc)
Defines an alias for a var: a new var with the same root binding (if
any) and similar metadata. The metadata of the alias is its initial
metadata (as provided by def) merged into the metadata of the original.

1 Example top

  • user=> (use 'clojure.contrib.def)
    nil
    user=> (defn square "Squares the given number" [x] (* x x))
    #'user/square
    user=> (defalias sq square)
    #'user/sq
    user=> (doc sq) ;; same metadata as original var
    -------------------------
    user/sq
    ([x])
      Squares the given number
    nil
    user=> (square 2)
    4
    user=> (sq 2)
    4
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/def.clj:66 top

(defmacro defalias
  "Defines an alias for a var: a new var with the same root binding (if
  any) and similar metadata. The metadata of the alias is its initial
  metadata (as provided by def) merged into the metadata of the original."
  ([name orig]
     `(do
        (alter-meta!
         (if (.hasRoot (var ~orig))
           (def ~name (.getRoot (var ~orig)))
           (def ~name))
         ;; When copying metadata, disregard {:macro false}.
         ;; Workaround for http://www.assembla.com/spaces/clojure/tickets/273
         #(conj (dissoc % :macro)
                (apply dissoc (meta (var ~orig)) (remove #{:macro} (keys %)))))
        (var ~name)))
  ([name orig doc]
     (list `defalias (with-meta name (assoc (meta name) :doc doc)) orig)))
Used in 0 other vars

Comments top

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