Transform a function's body into a string for mixing in

2019-06-20 Thread Emmanuelle via Digitalmars-d-learn
Hello! Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: --- __traits(getBody, (int a, int b) => a + b); // returns "(int a, int b) => a + b" // o

Re: Transform a function's body into a string for mixing in

2019-06-20 Thread Max Haughton via Digitalmars-d-learn
On Thursday, 20 June 2019 at 19:09:11 UTC, Emmanuelle wrote: Hello! Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: --- __traits(getBody, (int a, int b) => a + b); // returns "(int a, int

Re: Transform a function's body into a string for mixing in

2019-06-20 Thread Dennis via Digitalmars-d-learn
On Thursday, 20 June 2019 at 19:09:11 UTC, Emmanuelle wrote: Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: See: https://forum.dlang.org/post/kozwskltzidfnatbp...@forum.dlang.org If not,

Re: Transform a function's body into a string for mixing in

2019-06-21 Thread Emmanuelle via Digitalmars-d-learn
On Thursday, 20 June 2019 at 20:38:48 UTC, Dennis wrote: On Thursday, 20 June 2019 at 19:09:11 UTC, Emmanuelle wrote: Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: See: https://forum.dlan

Re: Transform a function's body into a string for mixing in

2019-06-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 June 2019 at 15:42:56 UTC, Emmanuelle wrote: Yeah, I want to be able to basically use mixin templates but with expressions instead, with the code being executed on the scope of the caller, not the callee; but it seems that's impossible without passing strings This sounds very si

Re: Transform a function's body into a string for mixing in

2019-06-21 Thread Emmanuelle via Digitalmars-d-learn
On Friday, 21 June 2019 at 15:54:35 UTC, Adam D. Ruppe wrote: On Friday, 21 June 2019 at 15:42:56 UTC, Emmanuelle wrote: [...] This sounds very similar to something I hacked together a while ago and recently wrote about making cleaner code: https://forum.dlang.org/post/ekbyseslunvmudkhl...@