<div dir="ltr"><div>pipeline operator may be confusing with bitwise operator.<br></div>In this case :<br>eggs = arg | spam | cheese<br><div><br></div><div>Is eggs a composed function or string of bits ?<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-09 21:15 GMT+02:00 Koos Zevenhoven <span dir="ltr"><<a href="mailto:koos.zevenhoven@aalto.fi" target="_blank">koos.zevenhoven@aalto.fi</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 2015-05-09 21:16, Steven D'Aprano wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On Sat, May 09, 2015 at 11:38:38AM -0400, Ron Adam wrote:<br>
<br>
</span><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
How about an operator for partial?<br>
<br>
root @ mean @ map $ square(xs)<br>
</blockquote></span>
Apart from the little matter that Guido has said that $ will never be<span class=""><br>
used as an operator in Python, what is the association between $ and<br>
partial?<br>
<br>
Most other operators have either been used for centuries e.g. + and - or<br>
at least decades e.g. * for multiplication because ASCII doesn't have<br>
the × symbol. The barrier to using a completely arbitrary symbol with no<br>
association to the function it plays should be considered very high.<br>
<br>
I would only support an operator for function composition if it was at<br>
least close to the standard operators used for function composition in<br>
other areas. @ at least suggests the ∘ used in mathematics, e.g.<br>
sin∘cos, but | is used in pipelining languages and shells and could be<br>
considered, e.g. ls | wc.<br>
<br>
My own preference would be to look at @ as the closest available ASCII<br>
symbol to ∘ and use it for left-to-right composition, and | for<br>
left-to-right function application. E.g.<br>
<br>
(spam @ eggs @ cheese)(arg) is equivalent to spam(eggs(cheese(arg)))<br>
<br>
(spam | eggs | cheese)(arg) is equivalent to cheese(eggs(spam(arg)))<br>
<br>
also known as compose() and rcompose().<br>
We can read "@" as "of", "spam of eggs of cheese of arg", and | as<br>
a pipe, "spam(arg) piped to eggs piped to cheese".<br>
</span></blockquote>
<br>
For me these are by far the most logical ones too, for exactly the same reasons (and because of the connection of @ with matrix multiplication and operators that operate from the left).<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It's a pity we can't match the shell syntax and write:<br>
<br>
spam(args)|eggs|cheese<br>
<br>
but that would have a completely different meaning.<br>
<br>
</blockquote>
<br>
<br></span>
But it does not need to have a different meaning. You could in addition have:<br>
<br>
spam @ eggs @ cheese @ arg # equivalent to spam(eggs(cheese(arg)))<br>
<br>
arg | spam | eggs | cheese # equivalent to cheese(eggs(spam(arg)))<br>
<br>
Here, arg would thus be recognized as not a function.<br>
<br>
In this version, your example of spam(args)|eggs|cheese would do exactly the same operation as (spam | eggs | cheese)(args) :-).<span class=""><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
David Beazley has a tutorial on using coroutines in pipelines:<br>
<br>
<a href="http://www.dabeaz.com/coroutines/" target="_blank">http://www.dabeaz.com/coroutines/</a><br>
<br>
where he ends up writing this:<br>
<br>
f = open("access-log")<br>
follow(f,<br>
grep('python',<br>
printer()))<br>
<br>
<br>
Coroutines grep() and printer() make up the pipeline. I cannot help but<br>
feel that the | syntax would be especially powerful for this sort of<br>
data processing purpose:<br>
<br>
# could this work using some form of function composition?<br>
follow(f, grep('python')|printer)<br>
<br>
<br>
<br>
</blockquote>
<br></span>
This seems promising!<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
-- Koos</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a></div></div></blockquote></div><br></div>