Dynamic alter-ego of D.

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Tue Oct 25 06:23:10 PDT 2011


I need an extremely fast and small typeless container for a single
object, which i can use to implement a fast and efficient dynamic
callback mechanism, where the exact number and types of parameters are
only known to the callback and to the source of the parameter values
and all intermediate manager classes, who hold and return the callback
do not know it.

On Tue, Oct 25, 2011 at 5:20 PM, Gor Gyolchanyan
<gor.f.gyolchanyan at gmail.com> wrote:
> Variant is heavy. It contains and does lots of things, that are not
> always required.
> a tiny type-less variable is versatile and can be used for any
> purposes. It's even type-safe in debug mode.
> Also, Variant needs explicit construction, whereas the tiny typeless
> variable automatically accepts any value.
> Also, Variant does not grant access to underlying raw data, but tiny
> typeless value can be taken address of (void*).
>
> On Tue, Oct 25, 2011 at 5:11 PM, Robert Jacques <sandford at jhu.edu> wrote:
>> 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