2 ms·
They are not equivalent. In Lisp there is no distinction between the syntax and the AST. In Haskell the AST is modeled using explicit data types. http://www.ha
by jgrant27 17y ago
They are not equivalent. In Lisp there is no distinction between the syntax and the AST. In Haskell the AST is modeled using explicit data types.
http://www.haskell.org/bz/thdoc.htm http://www.haskell.org/bz/thdoc.htm :
"In Template Haskell, ordinary algebraic data types represent Haskell program fragments. These types modeled after Haskell language syntax and represents AST (abstract syntax tree) of corresponding Haskell code. There is an Exp type to represent Haskell expressions, Pat – for patterns, Lit – for literals, Dec – for declarations, Type – for data types and so on. You can see definitions of all these types in the module Language.Haskell.TH.Syntax."
- jrockway 17y agoThis is a good thing, though. With Common Lisp, you have to emulate this via a code-walking library -- and because the code-walking library just uses heuristics, you can never be sure that your macro is right in all cases. With well-defined data types for each AST node, this problem goes away. The advantage that CL-style macros have is that they are much easier to use than TH. For me, anyway, writing a Lisp macro is a trivial thing that involves almost no thinking. Writing a TH macro takes some testing and debugging.
- jgrant27 17y agoThere's no need to 'emulate' anything 'via code-walking' and 'heuristics' when writing Lisp macros. This is a personal use case of your own. If you know how to write Lisp macros(i.e. experience) then they will be correct. Not all Lisp macros are trivial to implement even for the experienced Lisp hacker. Writing a Lisp macro requires testing and debugging. The difference is that Lisp inserts no 'airbags' between the language and the programmer. They are very powerful but you may 'hurt' yourself.
- jrockway 17y agoThe issue comes when transforming entire expressions; what parts are code to transform, and what parts are data? You can't know, you have to guess.
- jgrant27 17y agoThere is no guessing. You get to answer that question for yourself based on the context of your application. Many Lisps provide as much(or as little) type checking that you might want in your application.
- jrockway 17y agoOK, and now we've hit on the main problem I've had with Common Lisp -- every library thinks it's the only library in the universe, and they don't compose well. Your comment exactly expresses the attitude of the Common Lisp community (as I see it) -- "you should write every single line of code in your app from scratch, just for you". No thanks. The less code I have to write, the better.
- jgrant27 17y agoIt seems that you have a beef with a particular(or multiple) Common Lisp libraries. Fair enough. However, I never said that you should write every line of code in your app from scratch. I did say that you should OWN the decisions for YOUR app. I believe that this more accurately describes the attitude of the CL community (and that of many other languages too). My point was that meta-programming is more powerful in Lisp than Haskell(as far as I'm aware). That's pretty much it.
- deleted 17y ago[deleted]
- gwern 17y ago> If you know how to write Lisp macros(i.e. experience) then they will be correct. Is this the same argument as 'C is an insecure language only if you are a bad C programmer'?
- deleted 17y ago[deleted]
- jgrant27 17y agoNo. The statement simply means that experience is important. The same holds for any language that you use.
- anonymousDan 17y agoI don't understand what 'airbags' haskell inserts. Ok, it might be a bit trickier to write macros since it doesn't have such uniform syntax, but can you not still express all of the same meta-programming constructs?
- prodigal_erik 17y agoDoes that mean it's impossible to use Template Haskell to add new syntax? It strikes me as a serious limitation if you could only specify different ways to evaluate code that is already well-formed Haskell.
- dons 17y agoNo, you can add new syntax, via quasi quotes.