Dynamic alter-ego of D.
Robert Jacques
sandford at jhu.edu
Tue Oct 25 06:11:40 PDT 2011
On Tue, 25 Oct 2011 06:31:13 -0400, Piotr Szturmaj <bncrbme at jadamspam.pl> wrote:
> Gor Gyolchanyan wrote:
>> I think adding more dynamic typing to D would be a splendid idea to
>> further widen the variety of solutions for different problems.
>> Modular app development is a very good practice and modularity means
>> dynamicity, which in turn means, that one needs to give up on lots of
>> sweet stuff like templates, overloading and string mixins.
>> Variant is the first step towards dynamic alter-ego of D, which is
>> completely undeveloped currently.
>
> If Algebraic/Variant could be recognized by the language it would give
> some interesting possibilities, like Variant array literals:
>
> auto array = [10, 2.0, "abc"];
>
> types it as Algebraic!(int, double, string)[];
>
> auto AA = [ "a" : 10, "b" : 2.0, 3 : "abc" ];
>
> types it as Algebraic!(int, double, string)[Algebraic!(string, int)];
>
> for example, that may be used to express JSON structures with literals only:
>
> int x, y;
>
> auto json = [
> "x" : x,
> "y" : y,
> "colors" : [
> [
> r : 255,
> g : 0,
> b : 0
> ],
> [
> r : 0,
> g : 0,
> b : 255
> ]
> ]
> ]
Why do we need language support? This works in my variant proposal:
auto json = Variant(
"x",x,
"y",y,
"colors", [[
"r":255,
"g":0,
"b":0],[
"r":0,
"g":0,
"b":255]
]
);
Granted if ["r":255,"g":0,"b":0] weren't all int, it would have to be declared Variant("r",255,"g",0,"b",0), but we could always shorten Variant to var or something.
More information about the Digitalmars-d
mailing list