Erlang language issues

Raimo Niskanen <>
Wed Apr 17 08:53:47 CEST 2002


Luke Gorrie wrote:
> 
> "Chris Pressey" <> 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 as an optimisation - receive scans only the new messages when they
arrive, since the old messages are already known to not match.

And also - the putback() thing would disturb the order of received
messages for subsequent receive()s

/ Raimo Niskanen


> 
> And do timeouts :-)
> 
> Cheers,
> Luke



More information about the erlang-questions mailing list