[Python-ideas] Re: Function composition

2020-05-25 Thread Joao S. O. Bueno
Really, I don't think new syntax is needed for that, as it is trivially resolved by a function call (I would type an example but Ricky's answer covers it) Moreover, such a callable, or other helper-callables can trivially enable ways of connecting the piped values through specific (positional/nam

[Python-ideas] Re: Function composition

2020-05-24 Thread Ricky Teachey
Here's another whacky idea: how about adding a so-called FuncSeq to the collections library for composing functions? Since FuncSeq is (obviously) a sequence, that might help with the intuition of the function application order. The idea is the function application order is the same as the iteratio

[Python-ideas] Re: Function composition

2020-05-24 Thread Cameron Simpson
On 24May2020 19:28, David Mertz wrote: On Sun, May 24, 2020 at 6:56 PM Steven D'Aprano wrote: > I use bash a lot, and writing something like this is common: > cat data | sort | cut -d; -f6 | grep ^foo | sort -r | uniq -c And today's "Useless Use Of cat Award" goes to... :-) sort data |

[Python-ideas] Re: Function composition

2020-05-24 Thread Greg Ewing
On 25/05/20 3:27 am, Ram Rachum wrote: Speaking of evil, another evil idea would be to write code that modifies the ast and changes @ between functions to call a compose function instead. How do you tell just from the ast whether a particular @ is between functions? -- Greg ___

[Python-ideas] Re: Function composition

2020-05-24 Thread Dan Sommers
On Sunday, May 24, 2020, at 18:58 -0400, Chris Angelico wrote: > Maybe it's function call syntax that is the weird one. It might be > familiar to us, but maybe it's the one that's actually causing the > weirdness. Suppose we wrote the function last: > > (data)sort > > Now it's basically becom

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
On Sun, May 24, 2020, 9:03 PM Rob Cliffe via Python-ideas > In fact it's *more* intuitive than what we do now (evaluation is strictly > left-to-right), as can be seen with composed functions: > > ((path)str)len Forth was created in 1970. The idea isn't brand new. C is two years newer (197

[Python-ideas] Re: Function composition

2020-05-24 Thread Rob Cliffe via Python-ideas
On 24/05/2020 23:58, Chris Angelico wrote: Maybe it's function call syntax that is the weird one. It might be familiar to us, but maybe it's the one that's actually causing the weirdness. Suppose we wrote the function last: (data)sort Now it's basically become a pipeline. And yet this syntax lo

[Python-ideas] Re: Function composition

2020-05-24 Thread Michael Mitchell
JavaScript has an early proposal for this use-case: https://github.com/tc39/proposal-partial-application#pipeline-and-partial-application where "cat data | sort | cut -d; -f6 | grep ^foo | sort -r | uniq -c" could be represented as: data |> sort |> cut(?, delimeter=";", fields=6) |>

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
On Sun, May 24, 2020 at 6:56 PM Steven D'Aprano wrote: > > I use bash a lot, and writing something like this is common: > > cat data | sort | cut -d; -f6 | grep ^foo | sort -r | uniq -c > > And today's "Useless Use Of cat Award" goes to... :-) > > sort data | ... > > (What is it specifically

[Python-ideas] Re: Function composition

2020-05-24 Thread Chris Angelico
On Mon, May 25, 2020 at 8:54 AM Steven D'Aprano wrote: > > On Sun, May 24, 2020 at 06:31:46PM -0400, David Mertz wrote: > > > I think one thing that pulls in different directions is that both > > composition and piping are useful, and do something closely related. But > > in one the data "goes" f

[Python-ideas] Re: Function composition

2020-05-24 Thread Steven D'Aprano
On Sun, May 24, 2020 at 06:31:46PM -0400, David Mertz wrote: > I think one thing that pulls in different directions is that both > composition and piping are useful, and do something closely related. But > in one the data "goes" forward and in the other the data "goes backward." The same rule ap

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
Tiimmy: > Best I know, f@g applies g first in every language that implements a >> > composition operator, and in mathematics. While that may be arbitrary, >> it's easy to remember: (f@g)(x) "looks a heck of a lot more like" >> f(g(x)) than g(f(x)) >> > On Sun, May 24, 2020 at 5:39 PM Guido van R

[Python-ideas] Re: Function composition

2020-05-24 Thread Alex Hall
On Sun, May 24, 2020 at 11:17 PM Tim Peters wrote: > [Guido] > >> I’ve never been able to remember whether (f@g)(x) means f(g(x)) or > g(f(x)). That pretty much kills the idea for me. > > [David Mertz] > > Well, it means whichever one the designers decide it should mean. But > obviously it's a th

[Python-ideas] Re: Function composition

2020-05-24 Thread Guido van Rossum
Dang, you're right. It works as you'd expect without overthinking it. :-) I guess what has always (seriously, since my undergrad years studying math!) confused me is that somehow when this function is introduced they say (g*f)(x) = g(f(x)). The

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
On Sun, May 24, 2020, 5:11 PM Alex Hall > But when you *read* a call to filter(), it's generally pretty obvious > which argument is which, even if you don't remember the signature. You just > need to see which one's callable or which one's iterable (few things are > both). You can probably guess j

[Python-ideas] Re: Function composition

2020-05-24 Thread Tim Peters
[Guido] >> I’ve never been able to remember whether (f@g)(x) means f(g(x)) or g(f(x)). >> That pretty much kills the idea for me. [David Mertz] > Well, it means whichever one the designers decide it should mean. But > obviously it's a thing to remember, > and one that could sensibly go the other

[Python-ideas] Re: Function composition

2020-05-24 Thread Alex Hall
On Sun, May 24, 2020 at 10:53 PM David Mertz wrote: > On Sun, May 24, 2020, 3:43 PM Guido van Rossum wrote: > >> I’ve never been able to remember whether (f@g)(x) means f(g(x)) or >> g(f(x)). That pretty much kills the idea for me. >> > > Well, it means whichever one the designers decide it shou

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
On Sun, May 24, 2020, 3:43 PM Guido van Rossum wrote: > I’ve never been able to remember whether (f@g)(x) means f(g(x)) or > g(f(x)). That pretty much kills the idea for me. > Well, it means whichever one the designers decide it should mean. But obviously it's a thing to remember, and one that c

[Python-ideas] Re: Function composition

2020-05-24 Thread Guido van Rossum
I’ve never been able to remember whether (f@g)(x) means f(g(x)) or g(f(x)). That pretty much kills the idea for me. On Sun, May 24, 2020 at 11:10 Alex Hall wrote: > On Sun, May 24, 2020 at 6:56 PM David Mertz wrote: > >> On Sun, May 24, 2020 at 11:21 AM Steven D'Aprano >> wrote: >> >>> > But h

[Python-ideas] Re: Function composition

2020-05-24 Thread Alex Hall
On Sun, May 24, 2020 at 6:56 PM David Mertz wrote: > On Sun, May 24, 2020 at 11:21 AM Steven D'Aprano > wrote: > >> > But how would you go about getting a .__matmul__ attribute onto all >> > functions. For ones you write yourselves, you could decorate them at >> > definition. What about all the

[Python-ideas] Re: Function composition

2020-05-24 Thread David Mertz
On Sun, May 24, 2020 at 11:21 AM Steven D'Aprano wrote: > > But how would you go about getting a .__matmul__ attribute onto all > > functions. For ones you write yourselves, you could decorate them at > > definition. What about all the other functions though. > > As a functional programming fan,

[Python-ideas] Re: Function composition

2020-05-24 Thread Alex Hall
On Sun, May 24, 2020 at 4:55 PM David Mertz wrote: > Changed subject line. This is far from original topic. > > On Sun, May 24, 2020, 9:35 AM Ram Rachum wrote: > >> What's wrong with using @? If I understand correctly, it's used for >> matrix multiplication, which is far enough from function com

[Python-ideas] Re: Function composition

2020-05-24 Thread Ram Rachum
Speaking of evil, another evil idea would be to write code that modifies the ast and changes @ between functions to call a compose function instead. On Sun, May 24, 2020, 18:21 Steven D'Aprano wrote: > On Sun, May 24, 2020 at 10:49:45AM -0400, David Mertz wrote: > > > But how would you go about

[Python-ideas] Re: Function composition

2020-05-24 Thread Steven D'Aprano
On Sun, May 24, 2020 at 10:49:45AM -0400, David Mertz wrote: > But how would you go about getting a .__matmul__ attribute onto all > functions. For ones you write yourselves, you could decorate them at > definition. What about all the other functions though. As a functional programming fan, you m