On Tuesday, 4 September 2012 at 19:18:05 UTC, Jacob Carlborg wrote:
I've also wished quite many times I had dynamic typing in D.

I think we're *fairly* close with things like std.variant,
especially combined with some helpers. Take a look:

Variant a = 10;
string b = a; // can't, and I say that's good, usually
b = a.coerce!string; // works

But, to get a dynamic feel, you don't want to write
out coerce!type. I kinda want it to be auto. So,

Variant a = 10;
string b;

b.dset = a; // dset means dynamic set

This is pretty doable in D today.

auto dset(T, U)(ref T t, U u) {
        return t = to!T(u);
}

Then call with UFCS + property getter syntax.


The other thing is to do function calls. And we might
be able to pull that off too with something like

void foo(string a, string b) {}

auto dcall(alias func, T...)(T args) {
        import std.traits;
        ParameterTypeTuple!func typedArgs;
        foreach(i, ref arg; typedArgs)
                arg.dset = args[i];
        return func(typedArgs);
}

dcall!foo(a, b);



Thus your user code is pretty type-agnostic, with loose
types when requested.

Reply via email to