<br><br><div><span class="gmail_quote">On 1/2/07, <b class="gmail_sendername">Chris Rebert</b> <<a href="mailto:cvrebert@gmail.com">cvrebert@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In Haskell, foo `baz` bar means (baz foo bar), which translates to<br>baz(foo, bar) in Python. This allows Haskell programmers to use<br>functions as infix operators.<br>If I recall correctly, in Py3k, enclosing something in backticks will no
<br>longer cause it to be repr()-ed, leaving the backtick without a meaning<br>in Python.</blockquote><div><br>Right. I removed that back in August at the Google sprint. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thus, I propose one of the following as the new use for the backtick (`):<br>[Note: In both, the characters between the backticks must be a valid<br>Python identifier.]<br><br>(A) `baz` is treated as an operator, named "baz", just as / is "div".
<br>foo `baz` bar thus causes python to try to call foo.__baz__(bar), and<br>failing that, bar.__rbaz__(foo), and if both those fail, raise<br>TypeError. This is, if I understand correctly, how the builtin operators<br>
work.</blockquote><div> </div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(B) `baz` is a special way to call a callable. foo `baz` bar is
<br>translated to baz(foo, bar) with the standard lookup rules for<br>resolving "baz"<br><br><br>Example use cases, stolen from Haskell: The Craft of Functional Programming:<br>2 `max` 5 => 5<br>7 `cons` tail => ConsCell(val=7, next=tail)
<br>matrix1 `crossproduct` matrix2 => cross-product of the matrices<br>[1, 2, 3] `zip` ['a', 'b', 'c'] => [[1, 'a'], [2, 'c'], [3, 'c']]<br><br>I believe that this would improve the readability of code, such as
<br>Numeric, without going off the deep end and offering programmable syntax.</blockquote><div><br><br>Big -1 from me. I hate this feature from Haskell. It is a step towards programmable syntax and I think that's just a messy. And having it become a magic method that is called instead of just some function that takes two arguments really sends us down that road.
<br></div><br>-Brett</div>