Python syntax in Lisp and Scheme
Greg Ewing (using news.cis.dfn.de)
g2h5dqi002 at sneakemail.com
Thu Oct 23 01:09:00 EDT 2003
Jacek Generowicz wrote:
> Yes, you use flet (or labels) if you want a local function definition,
> and defun if you want a global one. Lisp caters for both
> possibilities. Does Python ?
If you mean the ability to have a nested function definition
that actually defines a top-level function, then yes, it
does...
Python 2.2 (#1, Jul 11 2002, 14:19:37)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
... global g
... def g():
... print "Urk!"
...
>>> g()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'g' is not defined
>>> f()
>>> g()
Urk!
>>>
Although I'm having a hard time imagining why you'd
actually *want* to do such a thing!
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list