[erlang-questions] Erlang vs Clojure

Kostis Sagonas kostis@REDACTED
Sat Nov 24 23:28:12 CET 2007


Ciprian Dorin Craciun wrote:
 > On Nov 24, 2007 11:28 PM, Kostis Sagonas <kostis@REDACTED> wrote:
 >>
 >> In what areas/applications the macro system is not doing what you
 >> want it to?  Some examples would help (at least me).
 >
 >     For example if I would like to execute a piece of code if a
 > condition is true and do nothing otherwise I have to write:
 >     if
 >         guard -> {do something}
 >         true -> false
 >     end
 >
 >     So instead of introducing a new control structure, I could define
 > a macro that would be used like you can see below, but is expanded
 > like the code above:
 >     if_ guard -> {do something} end
 >
 > I hope this is a good example even if it is a trivial one.

Yes, it's a good example alright, but this is something that can easily 
be done with the current macro system.  For example, in the HiPE native 
code compiler for Erlang we need similar functionality: doing some pass 
when a compiler option is specified and doing nothing otherwise.
So, we have the macro:

-define(when_option(__Opt,__Opts,__Action),
         case proplists:get_bool(__Opt,__Opts) of
           true -> __Action;
           false -> ok
         end).

and we use it all over the place as in e.g:

    ?when_option(verbose, Opts, ?debug_msg("Compiling ~w~n",[MFA])),

Is there something else that you want to do and you can't?

Kostis



More information about the erlang-questions mailing list