[Python-ideas] Proposal for function expressions (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Mon Jul 13 14:43:47 CEST 2009


Terry Reedy wrote:

Chris Perkins wrote:

First, a simple example to give the broad strokes: foo() do: BODY

is equivalent to: def ANON(): BODY foo(ANON) Add del anon and the equivalence is almost exact. Call all one-off functions '' and there is no need to ever delete the name and you have def (): body foo() which is nearly identical to your proposed foo(&).

You can even use decorator notation to move the call before the function body:

@foo def thunk(): BODY

(Note that most code block ideas haven't actually made it to the PEP stage - the only one along those lines that I can see in PEP 0 is PEP 359's "make" statement, which had more to do with metaclasses than code blocks. That said, I recall assorted code block based ideas being thrown around in the PEP 340/342/343/346 discussions that eventually lead to the introduction of PEP 343's with statement and PEP 342's generator enhancements)

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-ideas mailing list