C# 4.0 dynamic vs std.variant
Adam Ruppe
destructionator at gmail.com
Tue Jun 29 19:39:54 PDT 2010
If you want to play with dmdscript, I have a port to D2 here:
http://arsdnet.net/dcode/dmdscript_d2.zip
You have to compile it all at once: dmd *.d, instead of incremental,
or it won't link for some reason.
There's some hacks in that code, since I did the port using a dmd
release that had a broken in operator, and I haven't had the time to
go back and fix it since then. But, it should still work anyway.
The pretty.d file shows the beginnings of an opDispatch wrapper for
script objects. The biggest problem I had in making it work was
returning an object:
dynamic a;
a.b(); // works thanks to opDispatch calling through a lookup table
a.b.c(); // doesn't work, it complains about wrong number of args to
opDispatch, even if b is a property returning another dynamic
I don't know if this works in the new dmds. I haven't tried for a couple months.
I'm pretty sure D will be able to do most of what C#4 does with bug
fixes; no new features should really be necessary. One thing it can't
do is:
dynamic a = "hello"; // this might not compile due to opCall, but
break it into two lines and you can make it work
string b = a; // never gonna compile, arbitrary implicit casts aren't allowed
string b = a.coerce!string; // this is what std.variant does, works for me.
More information about the Digitalmars-d
mailing list