[erlang-questions] eep: multiple patterns

mats cronqvist mats.cronqvist@REDACTED
Fri May 30 11:00:00 CEST 2008


Richard A. O'Keefe wrote:
>
> 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.
>   
  very nice! if only i could compile it...


  mats



More information about the erlang-questions mailing list