Mixin template parameters / mixin template literals

"Luís "Luís
Wed Apr 24 17:06:03 PDT 2013


On Wednesday, 24 April 2013 at 23:42:57 UTC, Idan Arye wrote:
> Token strings solve all the problems the OP mentioned, but they 
> do not solve the one problem he didn't mention - closures:
>
>     int[] array = [3, 1, 5, 2, 7];
>     int x = 4;
>     writeln(array.filter!(a => a < x)()); // works as expected 
> and prints "[3, 1, 2]"
>     writeln(array.filter!q{a < x}()); // Error: undefined 
> identifier x

Yeah, it was unfortunate that the problems I exemplified could be 
solved by the token strings, without fulling solving the problem, 
making the issue seem more superficial than it is. Your example 
is better.

Notice that my code worked for your example, if you changed it to 
match your scenario:

     // we have to move this outside of main,
     // because the mixin template cannot be there
     int[] array;
     int x = 4;

     mixin template Greater() {
         auto Greater = () => a < x;
     }
     (...)

This seems to work. So, as I said, the infrastructure is there, 
we are just lacking the convenience of template mixin literals. 
Without that we have this unwieldy code, which otherwise seems 
fine.


More information about the Digitalmars-d mailing list