Python syntax in Lisp and Scheme

David Eppstein eppstein at ics.uci.edu
Wed Oct 15 12:50:38 EDT 2003


In article <tyfekxe32bi.fsf at pcepsft001.cern.ch>,
 Jacek Generowicz <jacek.generowicz at cern.ch> wrote:

> > To clarify, by "unlike lisp" I meant only that defun doesn't nest
> 
> ... and now you'll have to clarify what you mean by "defun doesn't
> nest" ...

The context of this was in accessing closures from function defs.
Maybe you can call defun from within another function, but it won't give 
you a closure.

> > of course you could use flet, or bind a variable to a lambda, or
> > whatever.
> 
> 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 ?

Yes.

def outer():
   x = 3
   global inner
   def inner():
      print x

outer()
inner()

...prints 3, as expected.

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science




More information about the Python-list mailing list