Is there a plan to add support for closures in CTFE?

Stefan Koch uplink.coder at googlemail.com
Tue Aug 16 12:53:55 UTC 2022


On Saturday, 13 August 2022 at 01:55:28 UTC, Andrey Zherikov 
wrote:
> I want to do string processing pipeline is a way that one 
> delegate calls another one and so on. This works perfectly 
> except the case when I want to get a result at compile time.
> So I wonder is there a plan to add support for closures at 
> compile time in foreseeable future?
> [ ... ]
>
> Note: I'm not asking for workarounds (I know how to do that), 
> I'm asking about the plan to fix this.

I am not clued in the official position on this, but I can tell 
you that it is not a trivial fix.
Due to the design of the interpreter at the moment.
That said it is also not impossible to do. What one would have to 
do is to allocate a pointer on the ctfe-entry and fill it with a 
closure chain once a closure is created.
when you then encounter the a usage of a closure variable you 
look up the frame in the closure chain and use the values from 
there.

It might be that I am missing something but that should be the 
basic flow of action.
I remember looking at that issue years ago but at the time I 
lacked the experience to fix it, and I was also focusing on the 
newCTFE interpreter.

Cheers,
Stefan


More information about the Digitalmars-d mailing list