Skip to content

Instantly share code, notes, and snippets.

@smeghead
Created April 12, 2011 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smeghead/915593 to your computer and use it in GitHub Desktop.
Save smeghead/915593 to your computer and use it in GitHub Desktop.
スコープテスト
% lua scope.lua
1
2
3
% python scope.py
Traceback (most recent call last):
File "scope.py", line 9, in <module>
print(c())
File "scope.py", line 4, in _counter
_count = _count + 1
UnboundLocalError: local variable '_count' referenced before assignment
def counter():
_count = 0
def _counter():
_count = _count + 1
return _count
return _counter
c = counter()
print(c())
print(c())
print(c())
function counter()
local _count = 0
return function()
_count = _count + 1
return _count
end
end
local c = counter()
print(c())
print(c())
print(c())
@fukata
Copy link

fukata commented Apr 12, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment