[erlang-questions] Concerning selective receive and channels

Richard A. O'Keefe ok@REDACTED
Thu Aug 14 07:58:21 CEST 2008

We've had a discussion about whether Erlang's selective receive is the  
in its grown or a wart that should be cured by the application of large
quantities of "channels".

I thought you might be as amused as I was to discover that there is a
programming language with a long history and about as wide a following  
Erlang where the analogue of a "channel" is a thing that can also do a
selective receive!

The language is Smalltalk.  The channel analogue is called a
"SharedQueue", and the basic operations are
     aSharedQueue nextPut: aMessage
     aMessage := aSharedQueue next.

This appears to be inherited from Smalltalk-80; at least both Squeak
and VisualWorks Non-commercial have the same class, and some of the
code is identical.  However, Squeak has added

     aMessageOrNil := aSharedQueue nextOrNilSuchThat: [:m | ...].

where the code in ... tests to see whether the message is the kind
it wants.  If there are any such messages, you get the first.  If
not, you get nil.

While VW doesn't have such a method, it adds a subclass of
SharedQueue called EventQueue with a sort of negative image:
anEventQueue removeEventsDestinedFor: aWindow
_discards_ messages of a particular kind.

So I'm picking that if we _did_ add channels to Erlang, not too long
afterwards we'd find ourselves adding selective receive to them.

More information about the erlang-questions mailing list