▲ | kscarlet 2 days ago | ||||||||||||||||||||||
It's easy to just stick them together, but to me (who writes too much Lisp for my own health) this is unsatisfactory. The dream: just like macro can be seen as a (staged) extension mechanism for Lisp evaluator, there should be an extension mechanism for the static type system, which allows me to define new types, define new syntax (like Haskell do-notation) which makes use of typing environment and expected type of current context (return-type polymorphism), etc. The reality: very few environments figure this out. In Coalton Lisp macros do work, but only at the level of untyped S-expr. A Lisp macro can't know about types of the variables in the lexical environment, or expected type of its own context. But it quite possibly works fine for the "typescript-like" use case you described. The problem I see: H-M type system isn't designed with extensibility in mind, and it's hopeless to make it extensible. More technical explanation of why it's hard to integrate with Lisp macro is that H-M relies on a unification-based inference stage which execution flow is very different from macro expansion. Possible solution: There's no fundamental reason why static type can't have something as powerful as Lisp macro. However first of all you would need an extensible type system, which seems to still be an open research problem. I think bidirectional type system is hopeful -- it's so different from H-M at a fundamental level though that I think it's hopeless to retrofit into Coalton. | |||||||||||||||||||||||
▲ | Xmd5a 2 days ago | parent | next [-] | ||||||||||||||||||||||
There are several ways to look at lisp macros but I think the most fundamental aspect is that they are hooks that allow one to run code at compile time in a dynamic compilation environment. In other words with lisp macros comes compile-time state. This is a big deal. Imagine the following piece of code:
With serveMQTT as a macro, we could store each mqtt topic, accepted args, etc ... into a compile-time datastructure. serveMQTTDoc, a macro too, would fetch the content of this datastructure, generate the documentation string for all mqtt topics at compile time, and return this string at run-time when queried.Compile-time state and a language that is also its own macro-language. That'd be a nice thing to have. | |||||||||||||||||||||||
| |||||||||||||||||||||||
▲ | JonChesterfield 2 days ago | parent | prev [-] | ||||||||||||||||||||||
What's the objection to putting type annotations on the macro, and refusing to compile code where the arguments to the macro don't match the type? | |||||||||||||||||||||||
|