3 ms·
> But if I'm trying to write a DSL, why would I need new syntax? You don't necessarily. But you'll need code generation to implement your domain-level abstract
by TeMPOraL 6y ago
> But if I'm trying to write a DSL, why would I need new syntax?
You don't necessarily. But you'll need code generation to implement your domain-level abstraction.
Within-programming domain example is OOP. CLOS is essentially a bunch of macros that bolts OOP on top of base Common Lisp. It unified and standardizes what was many experimental flavours of OOP systems that were also implemented as macros. Or e.g. pattern matching and logic programming - both implemented as libraries for CL, via macros.
Outside programming domain, I can imagine working with software e.g. simulating chemical reactions, where you'd want to have atoms, molecules, reactions, energy exchange, etc. as top-level concepts. You can of course model all these as data structures, classes, helper functions, etc. But Lisp macros allow you to take that and close up the abstraction, by building a clean interface that doesn't leak the underlying machinery. On top of that, you can shift that machinery to compile-time execution (but also reuse it at runtime).