Skip to content

Instantly share code, notes, and snippets.

@scizzorz
Created May 14, 2018 02:42
Show Gist options
  • Save scizzorz/9141f84b58be6852a1709efe2444ccf1 to your computer and use it in GitHub Desktop.
Save scizzorz/9141f84b58be6852a1709efe2444ccf1 to your computer and use it in GitHub Desktop.
# 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