[erlang-questions] Why doesn't Erlang has return statement?
黃耀賢 (Yau-Hsien Huang)
g9414002.pccu.edu.tw@REDACTED
Tue Dec 16 12:21:25 CET 2014
Hi, aman,
First, IMO, on Erlang, every function is real function, and every function
returns something, that it depends on you to check what returned. Though a
language with return statement guide programmers to check things returned
but ignore those functions without a return statement. The later one is
so-called 函式 in Chinese, a “function-like procedure.” It’s a weird concept
of some function without a return statement, that in definition it does not
return thing, but in memory of real computer system it return such as 0 but
actually it does not return 0 because the 0 is a symbol to represent
‘nothing'.
For the second question, how to avoid cascade case statement, there are at
least two way to do. The first way, case statement is similar to function
statement, and if some thing goes through many states in cascade case
statement, it seams to be some thing going through some functions and then
becoming some state. The second way, if items existing in cascade case
statement do not just occur in condition within case statement, layers of
case statement may be reduced by putting items together: for example,
case A of
ok -> case B of … end;
{error, _} -> …
end
may be arranged as
case {A, B} of
{ok, ok} -> …;
{{error, _}, _} -> …;
{_, {error, _}} -> …
end
/Y-H
On Tuesday, December 16, 2014, aman mangal <mangalaman93@REDACTED> wrote:
> 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
--
Best Regards.
--- Y-H. H.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141216/08e73417/attachment.htm>
More information about the erlang-questions
mailing list