In looking through the clojure.core file after the defmacro
definition you come to the following code:
(. (var defmacro) (setMacro))
What does this mean and do?
The meaning of .
is as explained by Joost's and Jeremy's answers. In case you're wondering about the details of what is accomplished by this particular method call:
This basically inserts a key called :macro
with the value true
into the metadata map of the Var whose name is clojure.core/defmacro
. The effect of this is that from this point on, if the compiler encounters the symbol defmacro
in a context where it resolves to the var #'clojure.core/defmacro
(#'foo
is shorthand for (var foo)
) -- which will normally be everywhere, though you could e.g. shadow this Var with a let
-bound local variable -- it will know that it should treat it as appropriate in the case of a name of a macro.
(Which is to say, either (1) expand the macro call using the function bound to #'clojure.core/defmacro
if the symbol defmacro
occurs in the operator position, i.e. immediately to the right of an opening paren, or else throw an exception to complain about a macro name being mentioned in non-operator position.)
Incidentally, the Clojure compiler routinely makes this sort of use of metadata maps on Vars, e.g. to decide on the types of various objects (cf. :tag
metadata) or whether to inline a function call (IIRC, :inline
and :inline-arities
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With