I was practicing writing macros and I can't seem to get defn
to work.
My syntax is: (my-define name parameter body)
Ignoring & parameters and recursive routines, How do I bind the name to a (fn[parameter] body)?
Clojure has a programmatic macro system which allows the compiler to be extended by user code. Macros can be used to define syntactic constructs which would require primitives or built-in support in other languages. Many core constructs of Clojure are not, in fact, primitives, but are normal macros.
You will need to transform
(my-define <name> <args> <body>)
to
(def <name> (fn <args> <body>))
This is quite simple actually:
(defmacro my-define [name args body]
`(def ~name (fn ~args ~body)))
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