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


Groups > comp.lang.python > #9127

Re: What makes functions special?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ericsnowcurrently@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'distinction': 0.07; 'rest,': 0.07; 'terry': 0.07; 'python': 0.08; 'defined,': 0.09; 'tracker': 0.09; 'wrote:': 0.15; '2:28': 0.16; 'asking.': 0.16; 'caching': 0.16; 'reedy': 0.16; '\xa0no': 0.16; 'cc:addr:python- list': 0.16; 'pm,': 0.16; 'that?': 0.19; 'language': 0.20; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'discussion': 0.22; 'header:In-Reply-To:1': 0.22; 'code.': 0.22; 'trying': 0.23; 'pieces': 0.23; 'code': 0.24; 'modules': 0.25; 'statement': 0.25; 'function': 0.26; 'url:mailman': 0.27; 'objects': 0.28; 'sat,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'compile': 0.29; 'object': 0.30; 'cc:addr:python.org': 0.30; 'definition': 0.30; 'module': 0.30; 'blocks': 0.30; 'modules,': 0.30; 'objects.': 0.30; 'subject:?': 0.31; 'url:listinfo': 0.32; 'pure': 0.32; 'actually': 0.33; 'there': 0.34; 'etc.)': 0.34; 'compilation': 0.35; 'do?': 0.35; 'module.': 0.35; 'subject:What': 0.35; 'file': 0.36; 'url:python': 0.37; 'issue': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'eric': 0.38; 'execution': 0.38; 'put': 0.38; 'case,': 0.38; 'case': 0.39; '[1]': 0.39; 'got': 0.39; 'received:209': 0.40; 'where': 0.40; 'happen': 0.62; 'body': 0.63; 'details': 0.65; 'received:209.85.215.174': 0.67; 'received:mail- ey0-f174.google.com': 0.67; 'special': 0.67; 'execution.': 0.84; 'phases': 0.84; 'special.': 0.84; 'snow': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=PWSndoFKgGS4AXJAcvhDRIB77TQn5nBZb2XPlJOtWLo=; b=m3SdEBU5O2mXIefFbVyOD67yMDoRsMQESW40mCPTCOfqM+e9x8Zno3RhPKqUAMF482 svM1hB2HI1MPeq7NtQ0bC7MsFAwwhYKT279Kpf6zxSxKo/p5rGXpBZNUTYEAnOTy1yG1 ujPq9XwJ5BNLWb9aSr59g7NR3xA+ZrY/Xg6D4=
MIME-Version 1.0
In-Reply-To <ivarbq$g20$1@dough.gmane.org>
References <CALFfu7Cd4jmZGfCPpz58Me+ar5w4O02x1TN9AtSMtkTK11Bsqg@mail.gmail.com> <ivarbq$g20$1@dough.gmane.org>
Date Sat, 9 Jul 2011 19:10:55 -0600
Subject Re: What makes functions special?
From Eric Snow <ericsnowcurrently@gmail.com>
To Terry Reedy <tjreedy@udel.edu>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.811.1310260259.1164.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310260259 news.xs4all.nl 21888 [2001:888:2000:d::a6]:48134
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9127

Show key headers only | View raw


On Sat, Jul 9, 2011 at 6:21 PM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 7/9/2011 2:28 PM, Eric Snow wrote:
>>
>> A tracker issue [1] recently got me thinking about what makes
>> functions special.  The discussion there was regarding the distinction
>> between compile time (generation of .pyc files for modules and
>> execution of code blocks), [function] definition time, and [function]
>> execution time.  Definition time actually happens during compile time,
>
> Not true. For main modules, execution of each statement immediately follows
> compilation, but not for other modules, where compilation and caching of
> code objects may happen years before the function object is created.
>

So for non-main modules the function definition happens during module
compilation, and for all other code blocks (__main__, exec, etc.) it
happens during execution of the code block?

>> Functions are a special case in Python for providing a more optimized
>> execution of a code block in pure Python code.  And how is that?  When
>> the function is defined, a code object is generated for the function
>> body along with a few "static" details that will be used during
>> execution.  No other objects have code objects.  No other objects in
>> Python have this special optimization.
>
> A .pyc file is a serialized code object for a module.
>

I hadn't thought of it like that.  Nice insight.  In that case, do
[non-main] module definition and execution time have the same logical
separation as function phases do?

> As for the rest, I am not sure what you are asking.
>

Yeah, I have a real knack for communicating.  :)  Mostly I am just
trying to put together more pieces of the Python puzzle.  In this case
I was trying to find out if the optimized execution of code objects
for functions is a part of the language or just an implementation
detail.

-eric

> Terry Reedy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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


Thread

Re: What makes functions special? Eric Snow <ericsnowcurrently@gmail.com> - 2011-07-09 19:10 -0600
  Re: What makes functions special? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-10 11:34 +1000
    Re: What makes functions special? Eric Snow <ericsnowcurrently@gmail.com> - 2011-07-09 20:33 -0600
    Re: What makes functions special? Terry Reedy <tjreedy@udel.edu> - 2011-07-10 00:04 -0700

csiph-web