Matching with std.concurrency receive
wiley.andrew.j at gmail.com
Sat Dec 10 12:05:34 PST 2011
On Sat, Dec 10, 2011 at 1:38 PM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Saturday, December 10, 2011 17:30:50 Adam wrote:
>> Hrm... that's a bit problematic. If I do use the exact match, it seems
>> to hang / lock up (probably the lack of support for classes?).
>> However, that's pretty much never the case of what I want to do, since
>> what I'm trying to do involves passing / accepting an interface and
>> its implementations.
>> I guess I can manage this with a static table of operation IDs
>> pointing to function delegates. Sadness. Haha
> It probably _should_ accept interfaces for classes and the like, but I don't
> think that it works properly for classes at the moment (due to issues with
> Variant), and in my experience, I've had use the _exact_ type, as annoying as
> that may be. For instance, if IIRC, I tried to pass a string which happened to
> be immutable, and when I tried to receive string on the other end, it wouldn't
> work until I changed it to receive an immutable string.
> If you have a type A which you think definitely should be receivable as type B
> on the other side, and it doesn't work, please submit a bug report:
> d.puremagic.com/issues . It's possible that you're misunderstanding something,
> but it's also definitely a possibility that receive just doesn't work right in
> some cases (e.g. far too strict). A bug report increases the chances of it
> getting fixed.
> - Jonathan M Davis
With classes, Variant currently can't handle immutability. Passing
shared objects is fine, and casting works as a workaround. The bug
report also has a workaround that's fairly easy to add to std.variant,
but it sounds like the current std.variant isn't going to get fixed
(just the replacement that's in development).
The thing that seems to be confusing about message passing is that we
have no dynamic pattern matching (and that's not because of receive,
it's because of Variant), so all type matching comes from templates
and checking types for equality. If you pass in a reference of type
Object, it doesn't matter what type the actual object is, you can only
match it as Object when receiving it.
This may or may not be unavoidable - if we can implement dynamic type
matching, classes will need to special cased in the Variant code
(because you can't dynamically typecheck a struct or primitive).
This is probably worth asking Rob Jacques about, since he's developing
the std.variant replacement.
More information about the Digitalmars-d-learn