[erlang-questions] is there "return" in Erlang.
Mon Feb 28 15:18:58 CET 2011
# Attila Rajmund Nohl 2011-02-28:
> 2011/2/28, Jachym Holecek <freza@REDACTED>:
> > And about return in general -- in Erlang (and other functional languages)
> > program is composed of expressions that get evaluated to values, there are
> > no statements. This is the reason why you do things like:
> > A = case (X rem 2) of
> > 0 ->
> > even;
> > 1 ->
> > odd
> > end
> > which quite annoyingly you can't do in C.
> I might misunderstand something, but
> A = (X % 2 == 0) ? even : odd;
> can be done in C ...
Oh, true, forgot about that -- but the one with 'if' can't, or consider
'switch' as another example. Point is in C, some things are statements
which do things without having a value themselves and some things are
expressions yielding values.
In Erlang, life is simpler -- everything is an expression, you can bind it
to a variable or just use it in-place anywhere an expression is allowed.
This means you can compose small bits of meaning in any way you want, free
from arbitrary limitations like the ones in C.
So "special" constructs in Erlang, like 'case' or 'if', are really just
syntactic sugar on top of lambdas (the strange scoping rule of 'case'
breaks the most straightforward approach to this, but can still be dealt
I think this is a very powerful property, although as you can see I have
a bit of a trouble in clearly expressing why is that. ;-)
More information about the erlang-questions