Dynamic alter-ego of D.

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Tue Oct 25 09:33:31 PDT 2011


> So delegate don't work because?

Delegates won't work this way because the parameters aren't bound and
are of unknown quantity and types.

> What about unions?

Unions allow only a limited number of types.

> Or casting a ptr into an array of raw bytes?

This won't always work, because static arrays must be converted to
dynamic arrays and structs of size, greater, then (2*size_t.sizeof)
must be passed by pointer. Otherwise it'll be the exact same thing as
i'm trying to say.

> Do you call the callback like 'dg();' or 'dg(x,y,z);'?

The second one. The callback takes arguments, only known to the one
calling it, not the one storing and returning it.

> At some level, either you hold the type in the type system, or as a tag somewhere.

Right, and all i'm trying to say is, that "somewhere" must be
customizable. Moreover, that "somewhere" may not exist along the
object's entire lifetime. The example with the dynamic callback showed
when the types are not stored.

On Tue, Oct 25, 2011 at 8:20 PM, Robert Jacques <sandford at jhu.edu> wrote:
> On Tue, 25 Oct 2011 11:45:48 -0400, Gor Gyolchanyan
> <gor.f.gyolchanyan at gmail.com> wrote:
>>
>> another example is dynamic callbacks.
>> You may carry around typeid of the function signature and a struct,
>> containing parameter values for it, which also contains the typeid of
>> it's target function's signature.
>> If you don't impose type information on the typeless values, i will be
>> able to check the types of the signatures (possibly by a hash value
>> for efficiency) and i won't need to check the types of each parameter
>> (since i'll be passing around array of typeless objects).
>
> I'm confused. So delegate don't work because? What about unions? Or casting
> a ptr into an array of raw bytes?
>
> Do you call the callback like 'dg();' or 'dg(x,y,z);'? If the latter, what
> about implicit variable conversions?
>
> At some level, either you hold the type in the type system, or as a tag
> somewhere.
>


More information about the Digitalmars-d mailing list