Common LISP-style closures with Python
rtomek at ceti.pl
Sat Feb 4 12:42:03 EST 2012
On Sat, 4 Feb 2012, Antti J Ylikoski wrote:
> On 4.2.2012 12:58, Arnaud Delobelle wrote:
> > On 4 February 2012 10:14, Antti J Ylikoski<antti.ylikoski at tkk.fi> wrote:
> > > On 4.2.2012 4:47, Chris Rebert wrote:
> > > > Out of curiosity, what would be non-Common-Lisp-style closures?
> > > >
> > > > Cheers,
> > > > Chris
> > >
> > >
> > > I understand that a "closure" is something which is typical of functional
> > > programming languages. -- Scheme-style closures, for example.
> > >
> > > I don't know Haskell, ML etc. but I do suspect that we could create
> > > closures
> > > in those languages as well. Maybe someone more expert than me can help?
> > I think what Chris asking is: what is the feature of Common-Lisp
> > closures that Python closures share but other languages don't?
> > I think what he is implying is that there is no such feature. Python
> > closures are no more "Common-Lisp-style" than they are "Scheme-style"
> > or "Smalltalk-like" or any other language-like.
> I would say that Python closures are equivalent with Common LISP closures
> (except that LAMBDA is more limited in Python, which is a feature which I
> don't like.)
> Do you maybe mean non-Common-LISP-style closures in Python? I cannot
> think of any ones.
> kind regards, Andy
AFAIK there is only one style for closure, similar to one style for
There are quite a lot languages implementing closures, and quite a lot try
to imitate them, including C with non-standard extension (without using
those imitations I cannot say if they are good enough).
Wrt lambdas, I really like blocks from Ruby (which AFAIK stem from blocks
in Smalltalk, not sure if they call them "blocks").
I mean, myself I am ok with lambdas (using them in languages where lambda
is welcomed and contributing citizen) but blocks in place of lambdas would
be nice to have in Python. Introduction of "with" construct was good IMHO,
but if one likes coding style relying on passing anonymous pieces of code
then Python might not be good choice for this.
On the other hand, one can argue that using anonymous code too much is not
the best style. I am not sure if extensive use of blocks/lambdas really
helps, or if it contributes to "clever" hacks and a source of maintainance
pain. So, perhaps it is good to have it in a few different ways -
like, Ruby, Python and CL - and experiment with them all.
In other words, rather than talking about making Python more like some
other language(s) I think it is much better to learn those other
language(s). If you'd like to try "unlimited" lambda, you might want to
play with Racket, a Scheme superset. Or any other Scheme - it's simple
enough to start coding after a day or two of learning (I mean Fibonaccis
and Erastotenes sieves, not implementing database or web server).
Myself, I would rather have blocks/lambdas and not need them rather than
the other way, but that's just me.
** A C programmer asked whether computer had Buddha's nature. **
** As the answer, master did "rm -rif" on the programmer's home **
** directory. And then the C programmer became enlightened... **
** Tomasz Rola mailto:tomasz_rola at bigfoot.com **
More information about the Python-list