[Python-ideas] Proposal for function expressions
MRAB
python at mrabarnett.plus.com
Tue Jul 14 17:26:27 CEST 2009
Chris Perkins wrote:
> On Tue, Jul 14, 2009 at 7:41 AM, Carl
> Johnson<cmjohnson.mailinglist at gmail.com> wrote:
>> This idea seems to be almost identical to my thread from November,
>> "Proposal for Ruby-style anonymous block functions (that don't kill
>> the indention)":
>> http://mail.python.org/pipermail/python-ideas/2008-November/002340.html
>
> Cool! I had not seen that thread, but the fact that you and I have
> proposed nearly the same thing independently increases the odds that
> I'm not just nuts. :)
>
>> The real difference is that your proposal uses & (which is a bad idea,
>> since & already has a meaning: __and__) and in
>>
>> foo() do:
>> BODY
>>
>> it implicitly injects the BODY function into the args of foo, which
>> violates Explicit Is Better Than Implicit.
>
> I considered the use of a "magic" placeholder character to be an
> unfortunate but necessary evil - the alternative seemed to be to
> restrict the block/def-expression to becoming the last argument to the
> function call that it follows, and that was just too restrictive. I
> have no particular attachment to "&" - but note that there is no
> ambiguity with the bitwise and operator, as far as I can tell. Eg.
> this works:
>
>>>> def f(a): return a()
> ...
>>>> 3 & f(&) do: return 5
> 1
>
> (not that you would write real code like that...)
>
[snip]
Another possibility is to permit a local name (it's not an anonymous
function any more!) so that you can have multiple functions:
3 & f(foo) def foo:
return 5
3 & f(foo, bar) def foo, bar:
return 5
and:
return 6
Anyway, how would you handle condition expressions, as used in 'if' and
'while' statements? /They/ also expect a terminating colon and an
indented block.
More information about the Python-ideas
mailing list