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

Mark Nijhof <>
Wed Dec 17 00:00:54 CET 2014


When I first started using Erlang I was missing the return statement as
well, in other languages return gave me an easy way to exit a function as
early as possible, i,e, when this thing is not true then don't continue but
exit. This kept the functions pretty clean.

Pattern matching has completely replaced this for me.

-Mark

On Tue, Dec 16, 2014 at 11:53 PM, Richard A. O'Keefe <>
wrote:
>
>
> On 16/12/2014, at 9:05 pm, aman mangal <> wrote:
> > 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)?
>
> What would you use a ‘return statement’ *for*?
> You might as well ask why Erlang doesn’t have an ‘assigned GO TO’
> statement.
>
> > Moreover, is there a good alternate to avoid nested case statements?
>
> Why avoid them?  Give a *real* example where nested case expressions
> (not “statements”, Erlang doesn’t strictly speaking *have* “statements”)
> are a problem.
>
> > Making more functions just seems tedious.
>
> That’s not the question, surely?  The question is whether it is *more*
> tedious than other alternatives.  And whether it leads to *better* code.
>
> > Using catch statement seems another good alternate but my intuition is
> that it is not good practice, is it?
>
> ‘try . . . catch’ is another ‘case’-like structure; that would be to
> cast out devils by means of Beelzebub.
>
> It seems to be a goood rule in all discussions like this to focus on
> some actual concrete cases from real code.
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>


-- 
Mark Nijhof
t:   @MarkNijhof <https://twitter.com/MarkNijhof>
s:  marknijhof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141217/4e9d2a80/attachment.html>


More information about the erlang-questions mailing list