[Python-ideas] Function Composition was:Re: (no subject)
Ron Adam
ron3200 at gmail.com
Fri May 8 19:10:49 CEST 2015
On 05/08/2015 12:13 PM, Chris Angelico wrote:
> On Sat, May 9, 2015 at 2:05 AM, Ron Adam<ron3200 at gmail.com> wrote:
>> >I don't think special syntax has an advantage over a function for this. It
>> >may even be a disadvantage. The problem with special syntax is it can't be
>> >represented as data easily. That would be counter to a functional style of
>> >programming, which seems at odds with the desired feature. (IMO)
>> >
>> > fns = (set, list, sorted)
>> > result = apply(data, *fns)
> There's no problem with representing it as data; just like elsewhere
> in Python, you can break out a subexpression and give it a name.
>
> (a @ b @ c)(x)
> # <=>
> f = (a @ b @ c)
> f(x)
>
> It's no different from method calls:
>
> sys.stdout.write("Hello, world!\n")
> # <=>
> write = sys.stdout.write
> write("Hello, world!\n")
That's good.
What advantage over using a function does the syntax have? So far it looks
fairly equal.
I think a function would be much simpler to implement, document, and
maintain. (Unless there are clear advantages to the syntax has that a
function doesn't.)
Cheers,
Ron
More information about the Python-ideas
mailing list