3 ms·
Most macros fall under one of three categories. Improving performance by removing function calls or doing work at compile time eg https://github.com/ztellman/v
by jamii 13y ago
Most macros fall under one of three categories.
Improving performance by removing function calls or doing work at compile time eg https://github.com/ztellman/vertigo https://github.com/ztellman/vertigo emulates c-style structs and uses macros to calculate the correct array offsets at compile-time, so you can treat a byte-array like a rich clojure datastructure but it compiles down to inline array access.
Controlling binding or control flow eg https://github.com/clojure/core.match https://github.com/clojure/core.match adds a pattern matching construct similar to those found in eg haskell or ocaml.
Rewriting code eg the core.async/go macro mechanically converts synchronous code into js-style callback code (examples - http://swannodette.github.io/2013/08/17/comparative/ http://swannodette.github.io/2013/08/17/comparative/ , internals - http://hueypetersen.com/posts/2013/08/02/the-state-machines-of-core-async/ http://hueypetersen.com/posts/2013/08/02/the-state-machines-...)
EDIT: In a lazy language like haskell, you can do most of that with lambdas, monad/arrow syntax and rewrite rules but the dsl syntax often ends up with just as much cognitive overhead as using a macro. Imagine how much less clear pattern matching would be in haskell if it was a library construct instead of having its own syntax.