4 ms·
FAQ: But what are macros for and why not functions? A: As you can see in the linked article, they do lots of things but macros are really useful for creating n
by roenxi 5y ago
FAQ: But what are macros for and why not functions?
A: As you can see in the linked article, they do lots of things but macros are really useful for creating new control structures. Things like threading macros (->), (and), (for), (time), etc.
It is difficult to create new control structures in languages that don't have good macros. Try implementing new flow control using functions and appreciate how hard it is.
This is why a lisp, like Clojure, can add new control structures using a library. Many languages struggle to do that and rely on some committee somewhere deciding it is a good idea.
- User23 5y agoTo add to this, if you grab SBCL or another free CL and dig around you’ll see a ton of the language is implemented as macros. I haven’t looked at the Clojure source but I imagine it’s similar.
- srcreigh 5y agoImagine adding an entire type system to the language as a library. That's what typed racket did (in 2014-ish?) with racket using macros.