[erlang-questions] erlang-questions Digest, Vol 12, Issue 98

John Haugeland stonecypher@REDACTED
Fri May 30 16:42:13 CEST 2008


Forgive my being naive.

Now let's do it with abstract patterns.
>
> #quit() ->       quit;
> #quit() ->       {?MODULE,{signal,{window1,_}}};
> #quit() ->       {?MODULE,{signal,{quit1,_}}}.
>
> #connect() ->    {?MODULE,{signal,{connect,_}}}.
>
> #disconnect() -> {?MODULE,{signal,{disconnect,_}}}.
>
> #show_about() -> {?MODULE,{signal,{about1,_}}}.
>
> #hide_about() -> {?MODULE,{signal,{dialog1,_}}};
> #hide_about() -> {?MODULE,{signal,{dialogb,_}}}.
>
> #data(Data)   -> {data,Data}.
>
>    loop(State) ->
>        receive
>            #quit()       -> quit()
>          ; #connect()    -> loop(conn(State))
>          ; #disconnect() -> loop(disc(State))
>          ; #show_about() -> loop(show_about(State))
>           ; #hide_about() -> loop(hide_about(State))
>          ; #data(Data)   -> loop(update(State, Data))
>           ; X             -> io:fwrite("got ~p~n", [X]),
>                             loop(State)
>        end.
>

So what's the advantage of that over something like this?

isa_quit(State) ->
    case State of
        {?MODULE,{signal,{window1,_}}} -> true;
        {?MODULE,{signal,{quit1,_}  }} -> true;
        _                              -> false
    end.

isa_hide_about(State) ->
    case State of
        {?MODULE,{signal,{dialog1,_}}} -> true;
        {?MODULE,{signal,{dialogb,_}}} -> true;
        _                              -> false
    end.

isa_connect(State)    -> case State of {?MODULE,{signal,{connect,_}}}    ->
true; _ -> false end.
isa_disconnect(State) -> case State of {?MODULE,{signal,{disconnect,_}}} ->
true; _ -> false end.
isa_show_about(State) -> case State of {?MODULE,{signal,{about1,_}}}     ->
true; _ -> false end.

wrap_data(Data) -> {data,Data}.

loop(State) ->
    receive RcvState -> if
        isa_quit(RcvState)       -> quit();
        isa_connect(RcvState)    -> loop(conn(State));
        isa_disconnect(RcvState) -> loop(disc(State));
        isa_show_about(RcvState) -> loop(show_about(State));
        isa_hide_about(RcvState) -> loop(hide_about(State));
        isa_data(RcvState)       -> loop(update(State, RcvState));
        X             -> io:fwrite("got ~p~n", [X]), loop(State)
    end end.

Everything's still named and abstracted, easier to maintain, update and
repair, but this doesn't require new syntax or compiler alterations.  So,
what am I missing?

  - John, who REALLY REALLY WANTS SELECTIVE EXPORT BADLY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080530/319551dc/attachment.htm>


More information about the erlang-questions mailing list