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


Groups > comp.lang.python > #9135

Re: What makes functions special?

References <CALFfu7Cd4jmZGfCPpz58Me+ar5w4O02x1TN9AtSMtkTK11Bsqg@mail.gmail.com> <ivarbq$g20$1@dough.gmane.org> <mailman.811.1310260259.1164.python-list@python.org> <4e1901bb$0$29994$c3e8da3$5496439d@news.astraweb.com>
Date 2011-07-09 20:33 -0600
Subject Re: What makes functions special?
From Eric Snow <ericsnowcurrently@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.816.1310265192.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jul 9, 2011 at 7:34 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Eric Snow wrote:
>
>> 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.
>
> You keep using that phrase, "optimized execution of code objects for
> functions", but I have no idea what that means.
>
> The best I can think of is that you are thinking along these lines...
>
> "Suppose we have the source code to a function:
>
> def spam(n):
>    return "SPAM"*n
>
> To execute this, Python currently compiles the function into a code block,
> and then when you call spam(n) elsewhere, Python executes the already
> compiled code block.
>

Yeah, that's pretty much it.  Is that all there is to it?  I was
saying optimized, but I guess there isn't much special optimization
going on then.  Thanks for taking the time.

-eric

> Suppose instead an implementation of Python did not pre-compile the
> function. Each time you called spam(n), the implementation would have to
> locate the source code and interpret it on the spot. Would that be
> allowed?"
>
> If that's your question, then I would call that a Python interpreter using
> c.1960 technology (as opposed to a byte-code compiler, which all the main
> implementations currently are).
>
> If that were the *only* difference, then I see no reason why it wouldn't be
> allowed as an implementation of Python. A horribly slow implementation, but
> still an implementation.
>
> However, I doubt that would be the only difference. Given such a
> simple-minded Python interpreter, it would be hard to provide expected
> Python language features such as compiled code objects, closures, etc. You
> would have to fake them somehow. Provided you could fake them sufficiently
> well, then the lack of a byte-code compiler is just a quality of
> implementation issue.
>
> If that's *not* your question, them I'm stumped.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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