[erlang-questions] Why doesn't Erlang has return statement?

Ola Bäckström <>
Tue Dec 16 10:59:18 CET 2014


> Moreover, is there a good alternate to avoid nested case statements? Making more functions just seems tedious.

Making new functions can actually be a good choice, if you find good names for them.

But if the expressions to make decisions on are non-expensive and without side effects you can make more compact case statemens by combining 2 (or more) expressions into one tuple.

Example with 2 nested:
case condition1() of
                            true ->
                                                          case condition2() of
                                                                                       true ->
                                                                                                                    doA();
                                                                                       false ->
                                                                                                                    ignore()
                                                          end;
false ->
                                                          ignore()
end

Simplified:
case {condition1(), condition2()} of
                             {true, true} ->
                                                          doA();
                             {C1, C2} when is_boolean(C1) andalso is_boolean(C2) ->
                                                          ignore()
end


> Using catch statement seems another good alternate but my intuition is that it is not good practice, is it?

I don’t see how catch statements can help out in this scenario, but definitely the more modern try-catch statements can be used if you need to catch something.

/Ola

From:  [mailto:] On Behalf Of aman mangal
Sent: den 16 december 2014 09:05
To: Erlang
Subject: [erlang-questions] Why doesn't Erlang has return statement?

Hi everyone,

I have seen similar questions before on the forum but I could never understand the reason behind it. Is it due to theoretical reasons such as return statement makes it hard to reason about the program or practical reasons that it is hard to implement it (this doesn't seem right but I cannot think of anything else)?

Moreover, is there a good alternate to avoid nested case statements? Making more functions just seems tedious. Using catch statement seems another good alternate but my intuition is that it is not good practice, is it?

Thank you
Aman Mangal
www.prism.gatech.edu/~amangal7<http://www.prism.gatech.edu/~amangal7>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141216/390e7037/attachment.html>


More information about the erlang-questions mailing list