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

Masklinn <>
Mon Feb 28 09:41:02 CET 2011


On 2011-02-28, at 04:55 , yted wrote:

> hello Wang:
> in fact "case" do work, like the codes below:
> 
> judge() ->
> A = getA(),
> B = getB(),
> case [A,B] of
> [CONF1, _] ->
> doSomeThing(A);
> [_, CONF2] ->
> doOtherThing(B);
> [_,_] ->
> doThings()
> end.
Yes, but 'tis not equivalent to the original code: `getA` and `getB` may have side-effects, in which case it would be expected that `getB` isn't executed if the first condition is true.

Closer to the original code would probably be along the lines of:

judge() ->
    case getA() of
        CONF1 -> doSomeThing(CONF1);
        _ ->
            case getB() of
                CONF2 -> doOtherThing(CONF2);
                _ -> doThings()
            end
    end.


More information about the erlang-questions mailing list