To make the question short, what is the reason why there is no return
statement in Elixir and some (most ? all ?) functional languages ?
To make it a bit longer, I'm facing a situation where in Java, Groovy, C, Ruby ... I would write some thing like
def func (some, parameters) {
# say some error
if(condition 1) {
return -1
}
# execute some function and return from here the result
if(condition 2) {
return process1(params)
}
# execute 'default' behavior when no condition matches and return result
process2(params)
}
Of course, this can be written as nested if
s but if the list of conditions is long, the code just gets unreadable.
I read the answers for the question Return statement in Elixir : they explain clearly how to implement this kind of pattern but not the reason of not having return
.
I believe having return
would break some FP concept but I wonder which ones and why.