[erlang-questions] quote, backquote and unquote in Erlang

ok ok@REDACTED
Tue Jun 26 02:25:01 CEST 2007


On 26 Jun 2007, at 3:57 am, Burkhard Neppert wrote:
> I'm new to Erlang and have a little lisp/scheme experience.

> Is there a way to do the same thing
> [as] scheme's quote, quasiquote (aka backquote) and unquote in Erlang?

There is nothing in Erlang's standard syntax to do this, although
someone (I forget who) HAS done something very similar and reported
it in this mailing list, so a trawl through the archives should turn
it up.

Quote is needed to prevent evaluation, but Erlang data do not look like
Erlang variables or function calls, so this is never needed.
It *is* possible to get the tokenised form of Erlang files or to get the
abstract syntax tree, and there *is* an interpreter for Erlang, used by
the shell.  So it is possible to treat Erlang code as data, but apart  
from
the shell, it really isn't common.

So in one sense the Erlang equivalent of
    (if (symbol? x) '(symbol) '(if full-moon? (howl) (whine)))
is
    if atom(X) -> [symbol]
     ; true    -> ['if','full-moon?',[howl],[whine]]
but in another sense such an Erlang equivalent doesn't really exist.

The main use of quasi-quote, unquote, and unquote-splicing is in macros
(not that 'unhygienic' macros are really part of Scheme), although I
have used them a lot in producing XML.  Erlang does not have Lisp-like
macros, although parse transforms can be used to the same end.  Erlang
has C-like macros (and how I wish it didn't), which are admittedly
inferior.  Again, trawl through the archives of this mailing list  
looking
for parse transforms, and you'll find stuff.  Someone had a rather nice
tutorial making it look so easy...





More information about the erlang-questions mailing list