5 ms·
The end result is relatively similar. Erlang has an underlying representation that uses something akin to prefix notation, albeit more verbose and a lot uglier
by mononcqc 17y ago
The end result is relatively similar. Erlang has an underlying representation that uses something akin to prefix notation, albeit more verbose and a lot uglier than what you'd get from lisp. Here's a blog post with an Erlang Abstract Syntax Tree described in it: http://seancribbs.com/tech/2009/06/20/building-a-parser-generator-in-erlang-part-4/ http://seancribbs.com/tech/2009/06/20/building-a-parser-gene...
In essence, this can get close to lisp macros; with parse-transforms, some people have developed modules as objects, qlc (querying an mnesia database as a list comprehension), cancelling out single assignment, etc.
The ways to do this are rather obscure and not too documented. I think that it's a bit fortunate (arguably) because it makes it harder for people to build illegible macro systems.
- gruseom 17y agoI'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.
- mononcqc 17y agoIf 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 http://github.com/rvirding/lfe). Edit: here's the macro test file http://github.com/rvirding/lfe/blob/master/test/test_macro.lfe http://github.com/rvirding/lfe/blob/master/test/test_macro.l...