]> Devi Nivas Git - chevron.git/commit
Tokens needs to be a generator, not a list.
authornoah morrison <noah@morrison.ph>
Fri, 16 Jan 2015 15:52:47 +0000 (10:52 -0500)
committernoah morrison <noah@morrison.ph>
Fri, 16 Jan 2015 15:52:47 +0000 (10:52 -0500)
commit7f371e7e6293db55a43fa2ec97f498eb8b156c2c
tree9cac44d4c27a0bc22528044afa6dea9f6a914632
parent5c4d14f8a5c238b76bfc1ff84d7c9919f0447bda
Tokens needs to be a generator, not a list.

At first I thought they were pretty much the same thing.
But generators pick up from where they left off,
while lists don't.

This fixes the edge-case infinite loop
that was happening last commit.

from the python repl

Lists
>>> data = [1,2,3,4,5]
>>> for i in data:
...     print(i)
...     if i == 2:
...         for ii in data:
...             print('>', ii)
...             if ii == 4:
...                 break
...
1
2
> 1
> 2
> 3
> 4
3
4
5

Generators
>>> data = [1,2,3,4,5]
>>> gen = (d for d in data)
>>> for i in gen:
...     print(i)
...     if i == 2:
...         for ii in gen:
...             print('>', ii)
...             if ii == 4:
...                 break
...
1
2
> 3
> 4
5
chevron/renderer.py