[erlang-questions] Getting rid of some repetition.

Mats Cronqvist mats.cronqvist@REDACTED
Tue Mar 18 09:12:30 CET 2008


Colin Z wrote:
> Say I have a process loop with a receive block that receives a bunch 
> of different messages...typical scenario:
>
> loop(A, B, C)->
> receive
>  {msg1, A1}->
>   loop(A1, B, C)
> ;
> {msg2, B1}->
>   loop(A, B1, C)
> ;
> {msg3, C1}->
>   loop(A, B, C1)
> ;
> {msg4, A2, C2}->
>   loop(A2, B, C2)
> end
 this idiom would reduce the typing;

loop(A0, B0, C0)->
  receive
   {msg1, A1}-> B1=B0,C1=C0;
   {msg2, B1}-> A1=A0,C1=C0;
   {msg3, C1}-> A1=A0,B1=B0;
   {msg4, A1, C1}-> B1=B0;
  end,
  loop(A1, B1, C1).

  the new syntax you propose is a bit too perly for my taste.

  mats
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mats_cronqvist.vcf
Type: text/x-vcard
Size: 179 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080318/74af9112/attachment.vcf>


More information about the erlang-questions mailing list