[Python-ideas] How do you think about these language extensions?
Chris Angelico
rosuav at gmail.com
Fri Aug 18 11:06:17 EDT 2017
On Fri, Aug 18, 2017 at 10:06 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> # arrow transform (to avoid endless parentheses and try to be more readable.
>>
>> >> range(5) -> map(.x->x+2, _) -> list(_)
>> >> [2,3,4,5,6]
>
> I like the idea of chained function calls, like pipes in shell
> languages such as bash. I've written a proof-of-concept for that:
>
> http://code.activestate.com/recipes/580625-collection-pipeline-in-python/
>
> I prefer | to -> but that's just a personal preference.
>
> I don't like the use of _ in there. Underscore already has a number of
> special meanings, such as:
>
> - a convention for "don't care"
>
> - in the interactive interpreter, the last value calculated
>
> - used for internationalisation
>
> I don't think that giving _ yet another special meaning, and this one
> built in to the language, is a good idea.
AIUI it's not a new meaning, but another variant of the second of
those examples: it means "the last value calculated". However, I'd
prefer to see it done with something that's otherwise illegal syntax -
so unless the expression is to the right of a "->", you cannot use
that symbol in that way. I'm on the fence as to whether it'd be better
to allow an implicit last argument (or implicit first argument), so
you can say "-> list()" without the symbol.
ChrisA
More information about the Python-ideas
mailing list