On 06/08/2015 10:16 PM, Idan Arye wrote:
On Monday, 8 June 2015 at 20:02:11 UTC, Andrei Alexandrescu wrote:
Walter and I are looking at ways to implement it. Here's a baseline
without static foreach - a "trace" function that prints function calls
before they are made:

http://dpaste.dzfl.pl/762c83c7fe30

If the function is overloaded, that won't work. In such cases, static
foreach might be helpful. Here's code from the cycle "I have a dream":

http://dpaste.dzfl.pl/82a70c809210

I'm trying to collect together motivating examples and to figure out
the semantics of the feature.


Andrei

How will scoping work? Similar to mixin templates?
...

I think the body should have access to a scope that is hidden from the outside which contains the loop variable, but declarations should be inserted into the enclosing scope like for static if.

It would be nice together with this feature to be able to mixin
identifiers:

     static foreach (ident; ["foo", "bar"])
     {
         auto mixin(ident)()
         {
             // code for foo/bar
         }
     }

Otherwise, other than overloads and template instantiations this won't
be much better then generating code strings with CTFE...

+1. Other use cases:

auto mixin(ident) = x;

identifier.list.mixin(ident).foo();

import std.mixin(ident);

Reply via email to