Hacker News new | past | comments | ask | show | jobs | submit login

ok so... why is writing an AST more ergonomic than having some syntax?



It’s really not. That’s part of the problem with lisp. But you can treat your code as a data structure which offers a lot of benefits. For instance, it’s basically impossible to offer control flow as a library in normal languages. That is, if you wanted to implement an unless statement like in Ruby, you’d have to use thunks or some other form of lazy evaluation. Macros allow you to just transform the unless statement into an if statement quite easily by just operating on the AST. Of course, you can do this without homoiconicity but it’s a lot less ergonomic.

Also part of the reason Babel exists is to take the place of a macro system. Instead of transpiling array spread into a function polyfill, macros would just output the pollyfill into the AST. What’s nice about this is that since it’s userland, people can test drive new features. Rust did that for async/await. And the pattern matching proposal in JS is based off a SweetJS macro.

(Obviously not all language features can be implemented as macros but you get my point, right)


i think so. thanks for the explainer!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: