Erlang language issues

Chris Pressey cpressey@REDACTED
Tue Apr 16 22:56:16 CEST 2002

James Hague wrote:
>>On a related note, is there a good reason for 'receive' to be a language
>>structure, rather than a BIF?  For example, instead of
>>  receive
>>    {foo, X} -> bar(X);
>>    {baz, Y} -> quuz(Y)
>>  end
>>couldn't one say, with identical intent,
>>  Msg = receive(),
>>  case Msg of
>>    {foo, X} -> bar(X);
>>    {baz, Y} -> quuz(Y)
>>  end
>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
>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)

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...

>I think this is an interesting discussion, one which I unwittingly started
>:).  But I suspect that if you wrote down a comprehensive list of the
>polluted parts of Erlang (and not just pet peeves about the language
>design), it would be a fairly short list.  It might be longer if you
>all of OTP in that list, so junk like the crypto module could get a
>This would be a good document to have, I think.

Very true - most of the 'cruft' is in OTP.


More information about the erlang-questions mailing list