Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is attr-map needed in Clojure?

Tags:

clojure

I have looked through google and few books but couldn't find documentation about attr-map.

(c/defmacro ^:clojure-special-form throw
  "Throw to the catch for TAG and return VALUE from it.
  Both TAG and VALUE are evalled."
  {:arglists '([TAG VALUE])}
  [tag value]

Why is attr-map needed inspite of the params vector? Also can someone point me to a detailed resource about metadata in Clojure.

like image 635
navgeet Avatar asked Oct 31 '25 00:10

navgeet


1 Answers

It's not needed in that case. It's redundant.

user=> (defmacro ^:clojure-special-form throw   {:arglists '([TAG VALUE])} [tag value]   `(throw (Exception. ~tag ~value)))
#'user/throw
user=> (meta #'throw)
{:macro true, :ns #<Namespace user>, :name throw, :file "NO_SOURCE_PATH", :line 41, :arglists ([TAG VALUE]), :tag :clojure-special-form}

compare with:

user=> (defmacro ^:clojure-special-form throw [tag value]   `(throw (Exception. ~tag ~value)))
#'user/throw
user=> (meta #'throw)
{:macro true, :ns #<Namespace user>, :name throw, :file "NO_SOURCE_PATH", :line 43, :arglists ([tag value]), :tag :clojure-special-form}

See this explanation of special forms.

See also: Learning Clojure: Meta Data

like image 73
Diego Basch Avatar answered Nov 03 '25 21:11

Diego Basch