<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 10.5.2015 1:03, Gregory Salvan wrote:<br>
<blockquote
cite="mid:10001_1431209016_554E8437_10001_426_1_CAAZsQLCX=9d3n9h0TZ+K2pfaUFiNVCtCahbjMkeEJ6L2WXLZTg@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>Nobody convinced by arrow operator ?<br>
<br>
</div>
like: arg -> spam -> eggs -> cheese<br>
</div>
or cheese <- eggs <- spam <- arg<br>
<br>
</div>
<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
I like | a lot because of the pipe analogy. However, having a new
operator for this could solve some issues about operator precedence.<br>
<br>
Today, I sketched one possible version that would use a new ..
operator. I'll explain what it would do (but with your -> instead
of my ..)<br>
<br>
Here, the operator (.. or ->) would have a higher precedence than
function calls () but a lower precedence than attribute access
(obj.attr).<br>
<br>
First, with single-argument functions spam, eggs and cheese, and a
non-function arg:<br>
<br>
arg->eggs->spam->cheese() # equivalent to
cheese(spam(eggs(arg)))<br>
eggs->spam->cheese # equivalent to lambda arg:
cheese(spam(eggs(arg)))<br>
<br>
Then if, spam and eggs both took two arguments; eggs(arg1, arg2),
spam(arg1, arg2)<br>
<br>
arg->eggs # equivalent to partial(eggs, arg)<br>
eggs->spam(a, b, c) # equivalent to spam(eggs(a, b), c)<br>
arg->eggs->spam(b,c) # equivalent to spam(eggs(arg, b), c)<br>
<br>
So you could think of -> as an extended partial operator. And
this would naturally generalize to functions with even more
arguments. The arguments would always be fed in the same order as in
the equivalent function call, which makes for a nice rule of thumb.
However, I suppose one would usually avoid combinations that are
difficult to understand.<br>
<br>
Some examples that this would enable:<br>
<br>
# Example 1<br>
from numpy import square, mean, sqrt<br>
rms = square->mean->sqrt # I think this order is fine
because it is not @<br>
<br>
# Example 2 (both are equivalent)<br>
spam(args)->eggs->cheese() # the shell-syntax analogy that
Steven mentioned.<br>
<br>
# Example 3 <br>
# Last but not least, we would finally have this :)<br>
some_sequence->len()<br>
some_object->isinstance(MyType)<br>
<br>
-- Koos<br>
<br>
</body>
</html>