[erlisp-devel] receiving, pattern-matching

Faré fahree at gmail.com
Mon Aug 29 17:56:28 UTC 2005


Dear Eric,

On 29/08/05, Eric Lavigne <lavigne.eric at gmail.com> wrote:
> How does receive work? I see that one of the arguments is a pattern
> for indicating what sort of message I am interested in, but I don't
> understand how to write/interpret such a pattern. Also, will I receive
> only the first message that matches this pattern? What happens if no
> messages match the pattern? Returns nil immediately? Block until such
> a message arrives?

Erlisp should neatly decouple two things. (1) receiving, (2) matching.

Receiving is blocking, with an optional timeout. With a timeout of 0,
it's non-blocking. What you receive is a list.

You can then match this list agains patterns -- matching is the
natural way of expressing things in Erlang, but not so in Lisp. In
Lisp, you *can* use pattern matching. I've written a pattern matcher
(fare-matcher) with Erlang and ML in mind. Other matchers are
available (there's one in UCW, IIRC, and then there's Screamer).

What should happen when you receive something that doesn't match any
pattern? I don't remember what happens in Erlang: either the message
is dropped or it raises an error, I suppose (gotta read the
documentation). In Lisp, it could be configurable. See match vs ematch
just like we have case vs ecase.

> Better still, is there a way to set up a default handler that would
> perform predefined action whenever a message matching its pattern
> shows up?
The Erlang way of doing things would be to spawn another process for
the things you want to be done in background of your main process.
Remember: processes are cheap, in the Erlang model. Hopefully, so will
they eventually be with Erlisp (especially processes sleeping on a
receive).

[ François-René ÐVB Rideau | Reflection&Cybernethics | http://fare.tunes.org ]
<hcf> information we gather and create overflows our means of managing it
<hcf> our ppl r only happenstancely synergistic



More information about the Erlisp-devel mailing list