[dmd-concurrency] Pattern matching on message receives, error handling
Andrei Alexandrescu
andrei at erdani.com
Wed Jan 13 09:49:47 PST 2010
Sean Kelly wrote:
>> While I've intentionally made this as ugly (and self documenting) as
>> possible, I really have no idea how'd you'd clean this syntax up,
>> since I'm just not that familiar with D's introspection capabilites.
>> Does any one more familiar with D have a better way to implement
>> pattern matching?
>
> I'd imagine patterns typically use constants, so you could at least do something like this:
>
> receive( test("p1 == \"foo\" || p2 == 5)( (string a, int b) {...} ) );
>
> though this could still use a lot of improvement.
Guess you meant to close the quote like this:
receive( test("p1 == \"foo\" || p2 == 5")( (string a, int b) {...} ) );
But then again, what are we gaining compared to:
receive(
bool(string a, int b) { if (a != "foo" && b != 5) return false; ...} );
?
I agree that a nicer pattern matching would be nice to have, but that's
about it - "nice to have". It's not enabling.
That being said, it's worth looking into better ways of expressing
matches, be they via current language mechanisms or new.
Andrei
More information about the dmd-concurrency
mailing list