Skip to content

New for-loop #1

Description

@gvx

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions