Reimplementing the bulk of std.meta iteratively

Timon Gehr timon.gehr at gmx.ch
Fri Oct 2 11:56:32 UTC 2020


On 02.10.20 06:04, Walter Bright wrote:
> On 10/1/2020 5:41 AM, Timon Gehr wrote:
>> On 01.10.20 10:59, Walter Bright wrote:
>>> On 10/1/2020 12:51 AM, Timon Gehr wrote:
>>>> Maybe this is related to what you mean?
>>>>
>>>> type t = readln().strip()=="int"?int:double;
>>>> auto f = (t x)=>x;
>>>
>>>
>>> As D is a statically typed language, I don't see how that can ever work.
>>
>> The example is easy to type check statically. In terms of ABI, you 
>> just have to make sure that `f` can find the context pointer without 
>> already knowing the value of `t`, then it can reconstruct everything 
>> it needs to know.
> 
> I think you described D's "class" type. To make it work with int and 
> double, you'd need to "box" them with a class. Like Java.

No, you'd still pass them by value in appropriate registers or on the 
stack, but you only figure out at run time where the argument is 
actually located.


More information about the Digitalmars-d mailing list