[erlang-questions] eep: multiple patterns

Mats Cronqvist mats.cronqvist@REDACTED
Fri May 23 13:05:59 CEST 2008


Robert Virding wrote:
> Sorry for taking so long to comment this, but I have been thinking. 
> :-) Comments follow.
>
> 2008/5/16 Mats Cronqvist <mats.cronqvist@REDACTED 
> <mailto:mats.cronqvist@REDACTED>>:
[...]
>
>      i was reading virding's proposal as;
>
>     case bla of
>      Pat when true ->;
>      Pat when false->;
>      Pat ->
>        code()
>     end.
>
>      but that's not what he wrote...
>
>      in that case i propose the above. currently gives syntax error.
>
>
> I don't have a problem with this, but I don't really see the need. The 
> only time I have had repeated bodies they have been very simple no 
> repeating just them has been very straight forward.
[...]

  i read the above as "i've never needed this myself, so it must be 
unnecessary."
  let me assure you that there are major telecom equipment vendors whose 
code bases would benefit greatly from this syntax.
  although i (no longer) has access to that code, the pattern appears 
quite often in event-driven programming. here's a very small example 
from a simple GUI application;

loop(St) ->
    receive
    %% user deleted top window
    {?MODULE,{signal,{window1,_}}}       -> quit();
    %% user selected quit menu item
    {?MODULE,{signal,{quit1,_}}}       -> quit();
    %% user selected  connect menu item
    {?MODULE,{signal,{connect,_}}}       -> loop(conn(St));
    %% user selected  disconnect menu item
    {?MODULE,{signal,{disconnect,_}}} -> loop(disc(St));
    %% user selected about menu item
    {?MODULE,{signal,{about1,_}}}       -> loop(show_about(St));
    %% user clicked ok in about dialog
    {?MODULE,{signal,{dialogb,_}}}      -> loop(hide_about(St));
    %% user deleted about dialog
    {?MODULE,{signal,{dialog1,_}}}       -> loop(hide_about(St));
    %% we got data from the top_top process
    {data,Data}                       -> loop(update(St,Data));
    %% quit from the erlang shell
    quit                              -> quit();
    %% log other signals
    X                                 -> io:fwrite("got ~p~n",[X]),loop(St)
    end.




More information about the erlang-questions mailing list