On Wednesday, 5 March 2014 at 22:54:38 UTC, Andrei Alexandrescu
wrote:
On 3/5/14, 11:40 AM, Tofu Ninja wrote:
On Wednesday, 5 March 2014 at 18:58:49 UTC, Andrei
Alexandrescu wrote:
The one difficulty is figuring how to allow for all
iterations to stay
in the same scope, yet not have duplicate definitions of the
iteration
symbol. Probably worth a DIP. Other than that, we're a go.
Andrei
Do you have an idea of how to solve that? If not I have an
idea but it
is a little silly and it would introduce a new feature so I
would rather
wait and hear if there are any other solutions.
My idea revolves around replacing the iteration variable(s)
with the respective literal(s) before doing semantic analysis.
This is probably unprecedented.
Andrei
Forgive me if this has a real name, but what I think is needed is
some kind of partial scope construct. A way to declare a scope
for a specific symbol whilst still using it in the outside scope.
I think an example would make more sense than me trying to
explain it.
partial_scope
{
/*block A*/
//Things declared here are available in A and B
int val = 5;
}
{
/*block B*/
//Things declared here are available in B and the outside
scope
int x = val;
}
int y;
y = x; // works
y = val; // fails
Things declared in block A are available in block A and block B.
Anything declared in block B would be available in block B and
the outside scope. Things declared in block A are not available
in the outside scope.
With something like this, each iteration of the static foreach
would just be rewritten as a partial_scope with the iterator
declared in block A.