[Python-ideas] @return?

Conrad Irwin conrad.irwin at googlemail.com
Thu Apr 15 20:07:46 CEST 2010



On 04/15/2010 06:42 PM, spir ☣ wrote:
> On Thu, 15 Apr 2010 00:07:57 +0200
> Mathias Panzenböck <grosser.meister.morti at gmx.net> wrote:
> 
>> Maybe only allow them at certain places where they can be seen as an extension to an already 
>> existing statement syntax (not to an expression syntax):
>>
>> foo.bar = def(egg, spam):
>> 	pass
>>
>> return def(egg, spam):
>> 	pass
>>
>> yield def(egg, spam):
>> 	pass
> 
> This is more or less the same argument as what I stated in a previous post: the issue is a different, incompatible, format for func defs, compared to ordinary expression. The possible name prefixing the definition breaks the pattern. More precisely, "def" (or "function"/"method") should come just before the parameter list to allow a func def be used like any other expression.
> This won't change... but what about an alternative, like in Lua?
> 
It's hard to see that an alternative syntax for scoping a block is going
to be acceptable. A syntax like "@return", couple with expanding the
allowable forms of the def name solve many issues. Perhaps the only
remaining "missing" feature is passing functions to functions, though I
think that could be done with something like a "call" block:

call filter:
    def lt(x):
        return x < 2
    [1,2,3,4]

Which would work more elegantly if all functions had named parameters:

call filter:
    def fun(x):
        return x < 2
    seq=[1,2,3,4]

And it might be possible to restrict the contents of the block to only
be functions - somewhat reducing its functionality, but retaining the
"only one way to do it".

call partial(filter, seq=[1,2,3,4]):
    def fun(x):
        return x < 2

Conrad




More information about the Python-ideas mailing list