[erlang-questions] Erlang vs Clojure

Kostis Sagonas kostis@REDACTED
Sun Nov 25 00:29:02 CET 2007

Ciprian Dorin Craciun wrote:
>    It's not only about something you can or can not. It's also about
> aesthetics.

Yes.  I very much agree on this.  The only problem is that different 
people have different aesthetics.

(Btw, I am not the one who designed the macro system and I am far from 
enamoured by it, so I am not certain why I am currently defending it. 
But here is a response to your mail in any case.)

>    Compare the following two forms:
>    ?if_(guard, {do something})
>    vs
>    if_ guard -> {do something} end
>    Which one looks more natural?

Well, in Erlang, I would say it's definitely the first that looks more 
natural for the following two reasons:

  1. It looks like a function call, and function calls are very natural
     in a functional language.

  2. Erlang's if construct has totally different semantics than the ones
     you want there; it fails if the guard does not evaluate to true.

>    What if I want to execute two operations?
>    ?if_(guard, begin {operation-1}, {operation-2} end)
>    vs
>    if_ guard -> {operation-1}, {operation-2} end

You are making a good argument, but I'd say the best thing to do is to 
factor the two operations out in a function in such a case. (Actually, 
the only reason why you need the begin+end is that the ',' symbol is 
overloaded in Erlang).

>    What if I decide there is an else case? In my this case it's a
> matter of removing a character '_' and adding the true case. In your
> case I would have to rewrite a good portion.

Well, not really.  Your case would be something like:

   if guard -> {do something}; true -> {do something else} end

and in my case it would be a macro:

   ?if_else(guard, {do something}, {do something else}).

(and writing the new macro -- the ?if_ macro would be a special case 
where the true part is just the above macro with the else part 'ok')

>    The idea behind a good macro is to be able to "blend" inside the
> "built-in" syntax and not stand out.

I can give you many reasons why macros in Erlang suck but the "macros 
stand out in the language" argument comes pretty low on that list. I am 
not so convinced that Lisp-like macros is what Erlang desperately needs.
But then again, disagreements such as these are exactly the reason we 
have so many different and diverse programming languages...


More information about the erlang-questions mailing list