4 ms·
> Macros are fancy, but I've yet to come across a use case for it that can't be replaced with a simple function call. For starters, macros are mandatory for ou
by KingMob 8y ago
> Macros are fancy, but I've yet to come across a use case for it that can't be replaced with a simple function call.
For starters, macros are mandatory for out-of-order execution; anywhere you need arguments to be manipulated before evaluation must be done in a macro. E.g., a short-circuiting "or" function is impossible without being either a macro or built-in to the language.
Another common use case is efficiency. Any substantial computation you do at compile/eval-time never has do be done at runtime. I've worked on a Clojure router that compiles its nested route structure into efficient string-matching/regex code before it ever gets turned into machine code. Other languages either have to re-parse the routes, or find a way to cache a more efficient representation as part of an extra build step.