Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56588

Re: closure = decorator?

From Piet van Oostrum <piet@vanoostrum.org>
Newsgroups comp.lang.python
Subject Re: closure = decorator?
Date 2013-10-10 12:31 -0400
Message-ID <m2a9ihxf3a.fsf@cochabamba.vanoostrum.org> (permalink)
References <707e67a6-c398-4d0a-a058-76b8bf2829f0@googlegroups.com> <mailman.943.1381413788.18130.python-list@python.org> <qot8uy1rz4l.fsf@ruuvi.it.helsinki.fi>

Show all headers | View raw


Jussi Piitulainen <jpiitula@ling.helsinki.fi> writes:

> I don't actually know for sure what the most correct terminology is,
> but I like to think that a closure is a procedure (function) closed in
> the environment (namespace) where it was created, so even when it is
> called from another environment, it uses the one where it was born.

I usually say that a closure is a package, containing a function with
some additional data it needs. The data usually is in the form of name
bindings.

On the other hand, an object (instance) is a package containg data, with
one of more functions that work on this data.

So an object is more or less the dual of a closure, and in many cases
they can be used for the same purpose. In most programming languages the
difference is that closures can be called directly, whereas an object
needs to be used with a method call to do the same (this makes Java so
ugly in this area). In Python, however, you can define the __call__
method and with this they become almost identical in behaviour.
-- 
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

closure = decorator? Tim <jtim.arnold@gmail.com> - 2013-10-10 06:51 -0700
  Re: closure = decorator? Chris Angelico <rosuav@gmail.com> - 2013-10-11 01:03 +1100
    Re: closure = decorator? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-10 17:15 +0300
      Re: closure = decorator? Piet van Oostrum <piet@vanoostrum.org> - 2013-10-10 12:31 -0400
        Re: closure = decorator? Roy Smith <roy@panix.com> - 2013-10-10 20:04 -0400
          Re: closure = decorator? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-11 10:14 +0300
            Re: closure = decorator? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 09:24 +0000
              Re: closure = decorator? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-11 15:01 +0300
                Re: closure = decorator? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 16:44 +0000
                Re: closure = decorator? Terry Reedy <tjreedy@udel.edu> - 2013-10-11 16:51 -0400
              Re: closure = decorator? Franck Ditter <nobody@nowhere.org> - 2013-10-11 14:08 +0200
                Re: closure = decorator? Terry Reedy <tjreedy@udel.edu> - 2013-10-11 16:55 -0400
  Re: closure = decorator? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-10-10 17:08 +0300
  Re: closure = decorator? Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-10-12 13:54 -0700
    Re: closure = decorator? Tim <jtim.arnold@gmail.com> - 2013-10-14 09:39 -0700

csiph-web