|
|
|
|
|
by nanomonkey
2788 days ago
|
|
The benefits of macros and code as data is under appreciated. It allows you to remove boilerplate code, and simplify your thought process, which makes for easier to read code.
For example, in Clojure you can use macros to make a mini language that converts to HMTL at compile time: (defn index []
(html5
[:html
[:head]
[:body "the index-page"]]))
Or similarly create your route handler on the back end that will serve up your pages: (defroutes app-routes
(GET "/" [] (index))
(route/resources "/")
; if page is not found
(route/not-found "Page not found"))
Note how concise the language becomes, and this code will expand out to all of the necessary opening and closing tags or boiler plate code that makes your code safe and efficient. None of these syntax structures were previously in the language, they are instead created when needed for abstraction. |
|
Am I missing something? What's the special macro-ness here that is different from regular functions?