[erlang-questions] Why does Erlang have control structures?

Richard O'Keefe ok@REDACTED
Tue Aug 28 01:32:32 CEST 2012


On 28/08/2012, at 8:56 AM, Jayson Barley wrote:

> I am not sure I understand why we have them.


"if" is indeed a special case of "case",
and "case" is basically an in-lined function call.
And there is a hint:  if you are going to inline
a function call, what are you going to inline it
*as*?  The possibility must exist in the core
syntax, if nowhere else.

But "try" and "receive" couldn't be anything else.
Without "receive", we'd have to use channels.

> is_greater_than(X, Y) ->
>     is_true(X>Y).

That would never have worked in the Good Old Days,
where X > Y was a guard test and not usable in an
ordinary expression.

> I know that the control structures are a little bit faster, not much, but I find that the function form is more readable.

You will find it hard to get a consensus on that.




More information about the erlang-questions mailing list