Erlang language issues

Luke Gorrie luke@REDACTED
Tue Apr 16 23:12:55 CEST 2002


"Chris Pressey" <cpressey@REDACTED> writes:

> >Ah, but they're not the same!  In the second case you're always pulling a
> >message out of the mailbox.  In the first case, if the message doesn't
> match
> >one of the patterns, then it remains in the mailbox.
> 
> Good point.  A more accurate analogy would be
> 
>   Msg = receive(),
>   case Msg of
>     {foo, X} -> bar(X);
>     {baz, Y} -> quuz(Y);
>     _ -> putback(Msg)
>   end
> 
> And at that point, it's hard to see how this is any better than the built-in
> receive language structure.  In fact it's arguably worse, as it's quite easy
> to forget to put the message back...

It needs to do more still - receive scans the whole queue for a
message that matches the pattern, and if it finds one then removes
only it. If there isn't a match it has to block until new message(s)
are received, and then scan those with the same patterns.

And do timeouts :-)

Cheers,
Luke




More information about the erlang-questions mailing list