Python syntax in Lisp and Scheme

james anderson james.anderson at setf.de
Tue Oct 14 21:13:01 EDT 2003



David Eppstein wrote:
> 
> In article <eppstein-434779.17173814102003 at news.service.uci.edu>,
>  David Eppstein <eppstein at ics.uci.edu> wrote:
> 
> > > Isn't it true though that the lambda can only contain a single expression
> > > and no statements?  That seems to limit closures somewhat.
> >
> > It limits lambdas.  It doesn't limit named functions.  Unlike lisp, a
> > Python function definition can be nested within a function call, and the
> > inner function can access variables in the outer function's closure.
> 
> To clarify, by "unlike lisp" I meant only that defun doesn't nest (at
> least in the lisps I've programmed) -- of course you could use flet, or
> bind a variable to a lambda, or whatever.

? which lisps have you been using?

i do not observe the spec for defun
(http://www.lispworks.com/reference/HyperSpec/Body/m_defun.htm)
to place any restrictions on its context. anscillary discussion introduces the
issue of compile-time side-effects, eg whether the definition of the function
is known to exist for the purpose of error-checking, but there are no
constraints apparent to this reader on where the form may appear.

to wit


? (defun function1 (a)
    (defun function2 (b) (+ a b)))
FUNCTION1
? (function1 2)
FUNCTION2
? (function2 3)
5
? (function1 5)
FUNCTION2
? (function2 3)
8
? (defun function* (a list)
    (apply #'+ (mapcar (defun function2 (b) (+ a b)) list)))
FUNCTION*
? (function* 1 '(1 2 3))
9
? 

that is, both the invocation for side-effect and for the returned value appear
to have the intended effect. on the other hand, it's not clear why one would
want to do this, so perhaps you mean something else?

...




More information about the Python-list mailing list