fork(1) download
  1. def foo(x):
  2. a = x
  3. def bar():
  4. a += 1
  5. print a
  6. return bar
  7.  
  8. f = foo(3)
  9. try:
  10. f()
  11. except:
  12. print "Crap, integers in closures aren't assignable, since they're value types."
  13.  
  14. def foo2(x):
  15. a = [x]
  16. def bar():
  17. a[0] += 1
  18. print a[0]
  19. return bar
  20.  
  21. f2 = foo2(3)
  22. f2()
  23. f2()
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
Crap, integers in closures aren't assignable, since they're value types.
4
5