Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've written before that if you represented an AST as a data structure, wrote a function to transform one instance of that structure into another, and ran it at compile time, you'd have something close to Lisp macros. What's interesting about this Erlang example is that people are actually doing it. My suspicion is that it's more trouble than it's worth. The simplicity of the sexp representation and the fact that it's the same representation as the original language (no special notation for ASTs) are what make macros so natural in Lisp. Take away those properties and things will get messy quickly. But it might still be worth it for writing certain kinds of tools.


If you want to write lisp macros in Erlang, Robert Virding's Lisp Flavored Erlang might be what you look for: it's a lisp syntax on top of the Erlang VM (so it should be compatible with everything else) and it's supposed to support more powerful macros (http://github.com/rvirding/lfe).

Edit: here's the macro test file http://github.com/rvirding/lfe/blob/master/test/test_macro.l...




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

Search: