Created
May 14, 2018 02:42
-
-
Save scizzorz/9141f84b58be6852a1709efe2444ccf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# standard range func like in Python | |
range = fn(max) | |
cur = 0 | |
f = fn() | |
tmp = cur | |
if cur >= max | |
return | |
(*f).cur = cur + 1 | |
return tmp | |
return f | |
r = range(5) | |
print r() # 0 | |
print r() # 1 | |
print r() # 2 | |
print r() # 3 | |
print r() # 4 | |
print r() # null - end of iterator | |
print '---' | |
# mutate closure environment | |
r.cur = 10 | |
r.max = 13 | |
print r() # 10 | |
print r() # 11 | |
print r() # 12 | |
print r() # null - end of iterator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment