lhmouse/asteria

Generalize for-each loops

Closed this issue · 0 comments

At the moment for-each loops look like

for(each key, value -> container)
  // ...

There are two issues:

  1. Very often we only want value and not key, but we can't omit it.
  2. key and value are separated by a comma. We use a colon or equals sign elsewhere.

The proposal is to change

for-complement-range ::=
"each" identifier "," identifier "->" expression ")" statement

to

for-complement-range ::=
"each" identifier ( ( "," | ":" | "=" ) identifier ) ? "->" expression ")" statement

If the second identifier is omitted, then there will not be a key variable.