5 ms·
I think they have somewhat different use cases. Lisp's approach works best if you don't really want to analyze a fragment of code deeply, but just want to speci
by _delirium 15y ago
I think they have somewhat different use cases. Lisp's approach works best if you don't really want to analyze a fragment of code deeply, but just want to specify a new construct by looking one level deep in the AST, like the classic example of implementing "cond" or "if" as a macro.
But if you actually want to walk recursively down an AST, the fact that it's hard to get a usable AST in Lisp makes metaprogramming difficult and error-prone. For many uses, I don't really want the source code to a Lisp fragment, but the AST, in the sense of a semantically marked-up fragment that's resolved variable bindings and done all the other things a parser does.
Implementing a correct code-walker for Common Lisp is... really nontrivial. The best available one I've found is in Arnesi, http://common-lisp.net/project/bese/docs/arnesi/html/A_0020Code_0020Walker.html http://common-lisp.net/project/bese/docs/arnesi/html/A_0020C... Whereas walking a Haskell AST fragment is trivial.
- swannodette 15y agoHard to get a usable AST in Lisp? The ClojureScript analyzer is 500 lines of code. For all the meta-programming projects I've taken on - delimited continuations, embedded logic programming, and extensible pattern matching - I'll take Lisp data structures over the actual Lisp AST any day.
- Locke1689 15y agoAfter thinking about it, I agree. Sometimes that semantic information or metadata can be very useful in operation. Specifically, having typing information and pattern-matching can be a Godsend in many cases.