On Fri, Oct 27, 2017 at 8:46 AM, Mike Müller <mmuel...@python-academy.de>
wrote:

> This already exists in Coconut:
> http://coconut.readthedocs.io/en/master/HELP.html#function-composition
>
>
Quite funny to read that. It seems like they have made something like what
I proposed in the 2015 function composition threads, but without what I
considered improvements to it. I summarize the proposal below, but here's
also a link to it:

https://mail.python.org/pipermail/python-ideas/2015-May/033482.html

Indeed, a discussion was going on where many people were interested in
function composition syntax. Different variants had been proposed, and IMO
one of the most notable suggestions had been using the new matrix
multiplication operator. For example:

  from numpy import sqrt, mean, square

  rms = sqrt @ mean @ square

​  rms(values)  # == sqrt(mean(square(values)))​

And this can of course already be implemented for custom callables which
implement __matmul__.

But my email (linked above, and which might be a bit hard to read because
of the interleaved references to my previous proposal) was essentially
about something like this:

Assuming bar is a function that accepts at least one argument, make
foo..bar equivalent to types.MethodType(bar, foo). In other words, it would
create a bound method out of bar, with foo as self.

Not only would it allow calling a method which is not defined within the
class:

  values..square()

but it would also directly allow this:

  values..square()..mean(axis=2)..sqrt()

And even when the left-hand expression becomes the second argument for a
function/method:

car_door..car_key.turn() # equivalent to CarKey.turn(car_key, car_door)


-- Koos


PS. As you can see in the email linked above, I was already prepared to
just abandon the idea, because most likely it would be rejected. But what I
was not prepared for was the amount of *nonsense* arguments that were
thrown against it in that thread and elsewhere, and the whole thing got
turned into some kind of weird puzzle.




> From http://coconut-lang.org/:
> > Coconut is a functional programming language that compiles to Python.
> > Since all valid Python is valid Coconut, using Coconut will only extend
> > and enhance what you're already capable of in Python.
>
> Mike
>
> Am 26.10.17 um 13:06 schrieb Yan Pas:
> > I've looked up this feature in haskell. Dollar sign operator is used to
> avoid
> > parentheses.
> >
> > Rationalle:
> > Python tends to use functions instead of methods ( e.g.len([1,2,3])
> instead of
> > [1,2,3].len() ). Sometimes the expression inside parentheses may become
> big
> > and using a lot of parentheses may tend to bad readability. I suggest the
> > following syntax:
> >
> > len $ [1,2,3]
> >
> > Functions map be also  chained:
> >
> > len $ list $ map(...)
> >
> > This operator may be used for function composition too:
> >
> > foo = len $ set $
> > in the same as
> > foo = lambda *as,**kas : len(set(*as, **kas))
> > in current syntax
> >
> > Regards,
> > Yan
> >
>



-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to