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


Groups > comp.lang.python > #9127

Re: What makes functions special?

References <CALFfu7Cd4jmZGfCPpz58Me+ar5w4O02x1TN9AtSMtkTK11Bsqg@mail.gmail.com> <ivarbq$g20$1@dough.gmane.org>
Date 2011-07-09 19:10 -0600
Subject Re: What makes functions special?
From Eric Snow <ericsnowcurrently@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.811.1310260259.1164.python-list@python.org> (permalink)

Show all headers | 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