[erlang-questions] is there "return" in Erlang.

ok@REDACTED ok@REDACTED
Tue Mar 1 04:10:24 CET 2011


> Because that's not how his original program was flowing. His use of the C
> "return" keyword indicated to me that the flow was important. That there
> was a particular type of flow he couldn't figure out how to do, and *that*
> was what he was interested in. Not the function itself.

Yes, but the multiclause function does NOT mimic the flow of the original
bellower.  There _is_ a simple straightforward way to mimic arbitrarily
positioned use of 'return' in Erlang: wrap the body of the function in
a try..catch and replace 'return' by throw.

That's pretty much a perfect mimic, but it's not a good way to write the
code.  It's almost NEVER a good idea to take the flow of a C function and
try to mimic it in Erlang.  It is necessary to learn how to use Erlang
effectively, and then go back to what the function is supposed to mean
and restart writing new code in Erlang.

(There is of course a well known way to translate any arbitrary flow chart
into
pure functional code.  But you don't want to go there either.)
>



More information about the erlang-questions mailing list