[dmd-concurrency] Pattern matching on message receives, error handling

Kevin Bealer kevinbealer at gmail.com
Wed Jan 13 11:06:54 PST 2010


On Wed, Jan 13, 2010 at 1:55 PM, Andrei Alexandrescu <andrei at erdani.com>wrote:

> Sean Kelly wrote:
>
>> It's worth adding that Erlang does provide pattern matching capabilities
>> that have to be a run time in D, but I'm not sure this same capability is
>> available in Scala, for example.  In our case, this will probably be handled
>> manually by the user, with possibly some fancier way to do it later
>> (metaprogramming can do quite a lot in D).  For example:
>>
>>    receive(
>>        (int x) { ... },
>>        (string a, int b) { if (a == "blah") return false; ...; return
>> true; }
>>    );
>>
>> Here, the second function checks string a to see if it matches a pattern,
>> and returns true/false to indicate that there was a match.
>>
>
> For the OO crowd, I think this will be quite useful:
>
> class Handler
> {
>    bool receive(int x) { ... }
>    bool receive(int x, double y) { ... }
>    bool receive(string s, int x) { ... }
>    ...
> }
>
> auto h1 = new Handler;
> auto h2 = new Handler;
> receive(h1, h2); // dispatches automatically
>                 // starting from h1
>
> Sean, may I put this in confidence that you'll find the time to implement
> it? Walter, we may need some introspection chops for that too.
>
>
> Andrei


Also, what does it mean?

If I do this syntax:

 auto dg1 = void delegate(A x) { ... };
auto dg2 = void delegate(B x) { ... };

receive(dg1, dg2);

Does this mean receive anything that matches dg1, and if nothing is found,
receive anything that matches dg2?  Or does it mean to take the first
message in order that matches either one?

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-concurrency/attachments/20100113/62db27d2/attachment-0001.htm>


More information about the dmd-concurrency mailing list