Content deleted Content added
→Does Haskell allow functions as keys in a map?: show that mutable variables are handled correctly |
|||
Line 314:
</source>
: —''[[User:Ruud Koot|Ruud]]'' 11:32, 17 February 2011 (UTC)
: Also Pythons nested functions seem crippled compared to Scheme:
<source lang="python">
>>> def main():
... x = 1
... def f():
... x = x + 1
... print x
... return f
...
>>> o = main()
>>> o()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in f
UnboundLocalError: local variable 'x' referenced before assignment
</source>
: but only artificially and not fatally:
<source lang="python">
>>> def main():
... x = [1]
... def f():
... x.append(2)
... print x
... return f
...
>>> o = main()
>>> o()
[1, 2]
>>> o()
[1, 2, 2]
>>> o()
[1, 2, 2, 2]
>>> o()
[1, 2, 2, 2, 2]
</source>
: —''[[User:Ruud Koot|Ruud]]'' 11:57, 17 February 2011 (UTC)
|