ErlCee++

Luke Gorrie luke@REDACTED
Tue Jun 8 13:49:17 CEST 2004


Shawn Pearce <spearce@REDACTED> writes:

> Does the emacs LISP code for Erlang have selective receive?  I'm
> just wondering if there's any other "mainstream" langauge that actually
> has selective receive nicely worked into the environment.

Yeah. It's really easy: receive just scans the mailbox from newest to
oldest looking for a message that matches a clause. If it finds one
then it executes the clause, otherwise it it blocks until another
message arrives.

It could be optimized to only check each message once (i.e. only the
new ones) but O(n^2) has been okay for the Emacs hacking to date.

In the Elisp one you're forced to program in continuation-passing
style because processes don't save their stack between schedules. You
wouldn't have this problem with threads or Unix processes since each
"process" will have a private stack, instead of sharing one.

In essense the limitation means that each receive clause is a 'fun'
that gets called directly from the scheduler when a matching message
arrives. Anything that was on the stack when receive gets called is
just tossed away, so that it's only sensible to make tail-calls to
receive or receive-calling functions.

More discussion of this in my EUC paper:
  http://www.bluetail.com/~luke/distel/distel-euc.pdf

Generally I found Jonas Barklund and Robert Virding's draft "Erlang
specification" very handy for understanding how the runtime is
supposed to work:

  http://www.erlang.org/download/erl_spec47.ps.gz

-Luke




More information about the erlang-questions mailing list