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

MapAndFold mapandfold@REDACTED
Tue Mar 1 04:47:23 CET 2011


Hi,

I like such generalization. But I don't think it is general and clean enough.

My suggestion is composewhile. (The term "Compose" is from Mathematica)

composewhile([], Acc) ->
    Acc;
composewhile([F | T], Acc) ->
    case F(Acc) of
        {ok, Acc0} -> composewhile(T, Acc0);
        {stop, Acc0} -> Acc0
    end.

And we will arrange our job into steps like this:
stepA(Acc) ->
    A = getA(),
    case A == ?CONF1 of
        true ->
            doSomeThing(A),
            {ok, Acc};
        _ ->
            {stop, Acc}
    end.

stepC(Acc) ->
    doThings(),
    {ok, Acc}.

All composed together: composewhile([fun stepA/1, fun stepB/1, fun stepC/1], 0).

2011/2/28 黃耀賢 (Yau-Hsien Huang) <g9414002.pccu.edu.tw@REDACTED>:
>
>
>    test_seq( State, [] ) -> State ;
>    test_seq( State, [{S,O,F}|SOFs] ) ->
>        case compare(S, O, F) of
>            nil -> test_seq(State, SOFs) ;
>            Result -> manage(State, apply, F, [S])
>        end.
>
> that manage/N takes care of State.
>
> --
> Y.-H. H.
>

-- 
Best Regards,
mapandfold


More information about the erlang-questions mailing list