DIP 57: static foreach

Dicebot public at dicebot.lv
Mon Mar 10 06:08:17 PDT 2014


On Sunday, 9 March 2014 at 21:31:40 UTC, Timon Gehr wrote:
> http://wiki.dlang.org/DIP57/
>
> Thoughts?

1)

> Additionally, CTFE is invoked on all expressions occurring in 
> the ForeachAggregate

I think it can be phrased more universally "ForeachTypeList 
symbols must be evaluated as compile-time entities, if it is not 
possible, implementation-defined compilation error happens".

2) Saying that it does not introduce a new scope is not entirely 
true as symbols from ForeachTypeList should not be available 
outside of static foreach. You mention it later in the same block 
but it is important concept to define as we currently don't have 
such pseudo-scopes (do we?)

3)
> The body of the static foreach statement or static foreach 
> declaration is duplicated once for each iteration which the 
> corresponding foreach statement with an empty body would 
> perform when executed in CTFE

I don't understand the reason behind limiting static foreach to 
CTFE semantics. Simply evaluating and pasting the body for each 
iteration should be enough. It is much closer to mixin template 
instances in that regard.

This will also remove necessity to rely on shadowing rules to 
re-define ForeachTypeList symbols as at the time of pasting the 
body those won't exist anymore.

4)

>  Declarations introduced in the body itself are inserted into 
> this enclosing scope

Isn't "enclosing" term used only for scope-to-scope relations or 
it is applicable to any language construct? (I don't know)

5)

> For static foreach statements, break and continue are supported 
> and treated like for foreach statements over tuples.

It is impossible as far as I understand existing semantics. 
Currently placed continue/break refer to created scope and don't 
stop iteration over remaining template argument list members. 
This is not applicable to generic foreach.

6)

In "Iterating over members of a scope" example there is a strange 
Python-like colon after `static if` condition. Typo? :)

7)

In "Relation to tuple foreach" stating equivalency is not 
correct. It is more of subset and even not a strict one as 
semantics will differ in some corner cases. For example, 
iterating over expression list will create a local copy right now 
if `ref` is not used. I'd really want this to not be the case for 
static foreach.

Overall provided examples seem to much my expectations but 
semantics description can be more structured and detailed.


More information about the Digitalmars-d mailing list