updated from Atlas

This commit is contained in:
Luciano Ramalho
2015-04-01 22:48:56 -03:00
parent aab93699a4
commit 573e1a94c4
109 changed files with 5 additions and 6 deletions

36
attic/functions/accgen.py Normal file
View File

@@ -0,0 +1,36 @@
"""
Accumulator generator examples
http://www.paulgraham.com/accgen.html
>>> f3 = foo(3)
>>> f3(2)
5
>>> f3(2)
7
>>> f3(2)
9
"""
class foo0:
def __init__(self, n):
self.n = n
def __call__(self, i):
self.n += i
return self.n
def foo0(n):
def bar(i):
bar.s += i
return bar.s
bar.s = n
return bar
def foo(n):
def bar(i):
nonlocal n
n += i
return n
return bar