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.
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
(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)))
Comments top
No comments for defalias. Log in to add a comment.