[erlang-questions] Getting rid of some repetition.

Colin Z theczintheroc2007@REDACTED
Mon Mar 17 21:08:19 CET 2008


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
.


Is there a shorthand way to avoid having to repeat the calls to loop so many
times? I realize Erlang is functional and this is how you have to maintain
state, but it gets tedious typing all that out. It's especially burdensome
and error prone if I go back later and add or remove a parameter to loop,
because then I have to change it everywhere else, too.

It'd be cool if I could say something like loop(_,_,C1) and have the
compiler understand that I want to call loop with whatever the values of A
and B currently are.

Or even better, some syntax like loop(A:A2,C:C2) and it would know I wanted
to preserve B, but replace A and C with A2 and C2.

Is there any reason why something like this wouldn't be possible?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080317/253c6e57/attachment.htm>


More information about the erlang-questions mailing list