<div dir="ltr"><p dir="ltr">On Mar 20, 2014 8:16 PM, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br>
><br>
> On Thu, Mar 20, 2014 at 05:04:25PM -0400, Brandon W Maister wrote:<br>
><br>
> > Actually makes me think of decorators, which means that you wouldn't even<br>
> > need new tokens or keywords:<br>
><br>
> But you would require new syntax. Your suggested syntax<br>
><br>
> s = 'a' bop 'b'<br>
><br>
> is currently a syntax error.</p><p dir="ltr">100% agree, I was careful with my language, if not my thinking :-)<br></p><p dir="ltr"><br>
> Keep in mind that any changes to syntax would allow bop to be any<br>
> arbitrary object. Python cannot tell at compile-time whether bop is an<br>
> "operator" or a list or a string or a float, only at run-time.</p><p>I admit that when writing I didn't think about the fact that I was suggesting adding dynamic names to what is currently a static table.<br>
</p><p dir="ltr">> > from functools import make_operator<br>
> > bop = make_operator(b)<br>
><br>
> Do you have any suggestion as to how make_operator would work? What<br>
> should it do? </p><p dir="ltr">Originally I was thinking something along the lines of "just add it to the 'operators' dict" but obviously that won't work since there's no such thing.</p><p>
Before I defend the idea any further I need to point out that I don't think it's a *good* idea. I kind of like the idea of arbitrary infix functions, so I threw out an idea that I haven't seen before.</p><p>We could, hypothetically, create an "operators" dict (or dicts) alongside locals and globals. Then, if an unexpected token shows up in operator position (which is probably well-defined?) before a SyntaxError is raised the token is looked up in the operators dict.</p>
<p>I think that the biggest problem I have with that solution is that philosophically it seems like it would take Python a bit far into the lisp-2 camp, which I would not like.<br></p><p dir="ltr">> What sort of object is bop?</p>
A regular function that takes one or two args. Honestly the nice thing about the "look it up somewhere if it causes the right kind of SyntaxError" solution is that it would probably also allow arbitrary unary operators. Although why anyone would want *that* is beyond me, so maybe it's not nice :-)<br>
<div><p dir="ltr">bwm<br>
</p>
</div></div>