Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20147
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Common LISP-style closures with Python |
| Date | 2012-02-09 23:55 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <14449658.339.1328860523539.JavaMail.geo-discussion-forums@prly15> (permalink) |
| References | <dY_Wq.11747$I33.10275@uutiset.elisa.fi> |
在 2012年2月4日星期六UTC+8上午8时27分56秒,Antti J Ylikoski写道: > In Python textbooks that I have read, it is usually not mentioned that > we can very easily program Common LISP-style closures with Python. It > is done as follows: > > ------------------------------------- > > # Make a Common LISP-like closure with Python. > # > # Antti J Ylikoski 02-03-2012. > > def f1(): > n = 0 > def f2(): > nonlocal n > n += 1 > return n > return f2 > > ------------------------------------- > > and now we can do: > > ------------------------------------- > > >>> > >>> a=f1() > >>> b=f1() > >>> a() > 1 > >>> a() > 2 > >>> a() > 3 > >>> a() > 4 > >>> b() > 1 > >>> b() > 2 > >>> a() > 5 > >>> b() > 3 > >>> b() > 4 > >>> > > ------------------------------------- > > i. e. we can have several functions with private local states which > are kept between function calls, in other words we can have Common > LISP-like closures. > > yours, Antti J Ylikoski > Helsinki, Finland, the EU We are not in the 1990's now. A descent CAD or internet application now should be able to support users with at least one or more script languages easily. Whether it's javascript or java or flash in the browser-based applications, or go, python in the google desktop API, commercial SW applications to be able to evolve in the long run are not jobs from the publishers and the original writers of the SW packages only. I don't want to include a big fat compiler in my software, what else can I do ? LISP is too fat, too.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-04 02:27 +0200
Re: Common LISP-style closures with Python Chris Rebert <clp2@rebertia.com> - 2012-02-03 18:47 -0800
Re: Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-04 12:14 +0200
Re: Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-04 12:23 +0200
Re: Common LISP-style closures with Python Arnaud Delobelle <arnodel@gmail.com> - 2012-02-04 10:58 +0000
Re: Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-04 15:09 +0200
Re: Common LISP-style closures with Python Tomasz Rola <rtomek@ceti.pl> - 2012-02-04 18:42 +0100
Re: Common LISP-style closures with Python Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-04 17:52 -0500
Re: Common LISP-style closures with Python John O'Hagan <research@johnohagan.com> - 2012-02-05 12:31 +1100
Re: Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-05 06:19 +0200
Re: Common LISP-style closures with Python Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-05 13:58 -0700
Re: Common LISP-style closures with Python Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-02-06 07:55 +0200
Re: Common LISP-style closures with Python Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-05 15:29 -0800
Re: Common LISP-style closures with Python John Nagle <nagle@animats.com> - 2012-02-09 22:26 -0800
Re: Common LISP-style closures with Python 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-09 23:55 -0800
csiph-web