Draft Pep (was: Re: Let's Talk About Lambda Functions!)

Jonathan Hogg jonathan at onegoodidea.com
Tue Aug 6 13:21:22 EDT 2002


On 6/8/2002 16:50, in article
CfS39.62969$yc3.2160014 at bin4.nnrp.aus1.giganews.com, "Terry Reedy"
<tjreedy at udel.edu> wrote:

> 
> "Paul Rubin" <phr-n2002b at NOSPAMnightsong.com> wrote in message
> news:7xd6swhvit.fsf at ruckus.brouhaha.com...
>> "Terry Reedy" <tjreedy at udel.edu> writes:
>>> def fname params: body
>>> 
>>> is syntactic sugar for
>>> 
>>> fname = _internal_defun('fname', 'params', 'body')
>>> 
>>> that avoids have to quote stuff and write fname twice.  Same true
> of
>>> class and import statement.
>> 
>> What the heck is _internal_defun?  Typing it gets NameError in
> Python 2.2.
> 
> It's a hypothetical name that I made up!   It's also an alternative to
> your proposal that would have the same relation to def that
> __import__() (real name) has to import and that metaclass calls have
> to class.

Conveniently you didn't need to make it up:

>>> import new
>>> compile( 'print "hello"', '<nowhere>', 'exec' )
<code object ? at 0x412ce0, file "<nowhere>", line 1>
>>> fname = new.function( _, globals(), 'fname' )
>>> fname
<function fname at 0x411618>
>>> fname()
hello
>>>

[Of course the real case is much more complicated...]

Jonathan




More information about the Python-list mailing list