Cool, thanks for the examples.<br><br>The problem still remains of what happens when the function signature changes. <br>If loop/3 becomes loop/4, then we still have to change every "branch" of the receive block. I guess my gripe is that erlang doesn't feel very friendly from a refactoring standpoint. Some languages have default parameters for functions, and others you can avoid the whole situation by not having massive if/else, case, or, in this case, receive blocks.<br>
<br>I think the record example solves the issue, the only drawback being that you're forced to use a record.<br><br><div class="gmail_quote">On Tue, Mar 18, 2008 at 9:55 AM, Kenneth Lundin <<a href="mailto:kenneth.lundin@gmail.com">kenneth.lundin@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">On 3/18/08, Mats Cronqvist <<a href="mailto:mats.cronqvist@kreditor.se">mats.cronqvist@kreditor.se</a>> wrote:<br>
> Colin Z wrote:<br>
> > Say I have a process loop with a receive block that receives a bunch<br>
> > of different messages...typical scenario:<br>
> ><br>
> > loop(A, B, C)-><br>
> > receive<br>
> > {msg1, A1}-><br>
> > loop(A1, B, C)<br>
> > ;<br>
> > {msg2, B1}-><br>
> > loop(A, B1, C)<br>
> > ;<br>
> > {msg3, C1}-><br>
> > loop(A, B, C1)<br>
> > ;<br>
> > {msg4, A2, C2}-><br>
> > loop(A2, B, C2)<br>
> > end<br>
> this idiom would reduce the typing;<br>
><br>
> loop(A0, B0, C0)-><br>
> receive<br>
> {msg1, A1}-> B1=B0,C1=C0;<br>
> {msg2, B1}-> A1=A0,C1=C0;<br>
> {msg3, C1}-> A1=A0,B1=B0;<br>
> {msg4, A1, C1}-> B1=B0;<br>
> end,<br>
> loop(A1, B1, C1).<br>
><br>
> the new syntax you propose is a bit too perly for my taste.<br>
><br>
> mats<br>
><br>
</div></div>I think this is even better:<br>
<br>
loop(A0, B0, C0)-><br>
{A,B,C} =<br>
receive<br>
{msg1, A1}-> {A1,B0,C0};<br>
{msg2, B1}-> {A0,B1,C0};<br>
{msg3, C1}-> {A0,B0,C1};<br>
{msg4, A1, C1}-> {A1,B0,C1};<br>
<div class="Ih2E3d"> end,<br>
loop(A1, B1, C1).<br>
<br>
</div>Of course you could have called loop directly from the case alternatives<br>
as in the original example, but if each alternative need to do<br>
something more complicated I think this is clear and easy to<br>
understand.<br>
<br>
Mats example is actually more complicated in my view with all the ugly<br>
B1=B0, ... stuff.<br>
<font color="#888888"><br>
/Kenneth<br>
</font></blockquote></div><br>