www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C# 4.0 dynamic vs std.variant

reply Jesse Phillips <jessekphillips+D gmail.com> writes:

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
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Jesse Phillips:



for D2 to fix its bugs and finish to implement the planned features). Bye, bearophile
Jun 29 2010
parent Jesse Phillips <jessekphillips+D gmail.com> writes:
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
prev sibling parent reply Lutger <lutger.blijdestijn gmail.com> writes:
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 to

 
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.
Jun 29 2010
parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
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
parent reply Adam Ruppe <destructionator gmail.com> writes:
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
parent Lutger <lutger.blijdestijn gmail.com> writes:
Adam Ruppe wrote:

 If you want to play with dmdscript, I have a port to D2 here:
 http://arsdnet.net/dcode/dmdscript_d2.zip
Super! 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