digitalmars.D - C# 4.0 dynamic vs std.variant
- Jesse Phillips (5/5) Jun 29 2010 I found a simple article on the coming 'dynamic' type for C# 4.0[1]. I d...
- bearophile (5/7) Jun 29 2010 C#4 dynamic attribute is better than anything D has (but currently it's ...
- Jesse Phillips (3/7) Jun 29 2010 Agreed, I'm more curious if opDispatch would work for a type who's "type...
- Lutger (6/20) Jun 29 2010 TPDL discusses briefly how such a dynamic type can be implemented with
- Jesse Phillips (3/8) Jun 29 2010 Shhhh, don't ruin the surprise I haven't gotten that far yet.
- Adam Ruppe (22/22) Jun 29 2010 If you want to play with dmdscript, I have a port to D2 here:
- Lutger (5/38) Jun 30 2010 Super! thanks.
think I would find anything interesting about it since D already has std.variant. There were two things of interest. 1) The possibility of mixing dynamic languages in the same code as static (like ASM in D). 2) When a function is called on a dynamic type, the call is checked at run-time to see if the call is valid. The second should be doable using opDispatch? And it would be checked at compile-time instead of run-time. Wouldn't that be a good addition to 1. http://www.hanselman.com/blog/C4AndTheDynamicKeywordWhirlwindTourAroundNET4AndVisualStudio2010Beta1.aspx
Jun 29 2010
Jesse Phillips:for D2 to fix its bugs and finish to implement the planned features). Bye, bearophile
Jun 29 2010
bearophile Wrote:Better dynamic support than D, but surely not anything D has.(but currently it's better for D2 to fix its bugs and finish to implement the planned features).Agreed, I'm more curious if opDispatch would work for a type who's "type" keeps changing.
Jun 29 2010
Jesse Phillips wrote:think I would find anything interesting about it since D already has std.variant. There were two things of interest. 1) The possibility of mixing dynamic languages in the same code as static (like ASM in D). 2) When a function is called on a dynamic type, the call is checked at run-time to see if the call is valid. The second should be doable using opDispatch? And it would be checked at compile-time instead of run-time. Wouldn't that be a good addition toTPDL discusses briefly how such a dynamic type can be implemented with opDispatch and std.variant. The dynamic from TDPL also resolves method calls at runtime, and can add new methods at runtime too. It should be possible to add a dynamic language interpreter such as dmdscript to the mix, sounds like a fun experiment.
Jun 29 2010
Lutger Wrote:TPDL discusses briefly how such a dynamic type can be implemented with opDispatch and std.variant. The dynamic from TDPL also resolves method calls at runtime, and can add new methods at runtime too. It should be possible to add a dynamic language interpreter such as dmdscript to the mix, sounds like a fun experiment.Shhhh, don't ruin the surprise I haven't gotten that far yet. The book is great!
Jun 29 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. 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.
Jun 29 2010
Adam Ruppe wrote:If you want to play with dmdscript, I have a port to D2 here: http://arsdnet.net/dcode/dmdscript_d2.zipSuper! thanks.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 think this was fixed.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.
Jun 30 2010