lambda_module_T603.pyx 440 Bytes
Newer Older
Stefan Behnel's avatar
Stefan Behnel committed
1 2
# mode: run
# tag: lambda
3
# ticket: 603
Stefan Behnel's avatar
Stefan Behnel committed
4

5
# Module scope lambda functions
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
__doc__ = """
>>> pow2(16)
256
>>> with_closure(0)
0
>>> typed_lambda(1)(2)
3
>>> typed_lambda(1.5)(1.5)
2
>>> cdef_const_lambda()
123
>>> const_lambda()
321
"""

pow2 = lambda x: x * x
with_closure = lambda x:(lambda: x)()
typed_lambda = lambda int x : (lambda int y: x + y)

cdef int xxx = 123
cdef_const_lambda = lambda: xxx

yyy = 321
const_lambda = lambda: yyy