deja icon indicating copy to clipboard operation
deja copied to clipboard

New for-loop

Open gvx opened this issue 12 years ago • 0 comments

Currently, for-loops are simple beasts. The syntax is like this:

 for NAME ITERATOR:
     BODY

I want to change it to:

for NAME1 NAME2 ... in ITERABLE:
    BODY

This change would consist of four changes:

  1. Allowing multiple names for iterating over multiple values at the same time (like with Python's enumerate()).
  2. Adding in as a pseudo-keyword to separate the names from the rest. The word in would only be treated differently in the head of a for-loop.
  3. For-loops will work with iterables instead of iterators, which means that before the loop, the TOS will be checked for its type, and a certain iterator will be called. For lists, this will be a new version of in.
  4. This one is less visible: the iterator will no longer get a "hidden" argument, so state will have to be kept in another way (most likely with local variables and the use of yield).

gvx avatar Dec 21 '13 16:12 gvx