PROPOSAL: opSeq()

Russell Lewis webmaster at villagersonline.com
Wed Apr 9 10:19:56 PDT 2008


Frits van Bommel wrote:
> Well, one ambiguity is stuff like: "foo 1 -2". Is this foo.opSeq(1 - 2) 
> (i.e. foo.opSeq(-1)) or foo.opSeq(1, -2)?
> Ditto for '~' (concatenation versus bitwise negation), '&' (bitwise-and 
> versus address-of), '!' (template instantiation versus logical 
> negation), '.' ("member of" versus "look up in the global scope"), '+' 
> (addition versus numeric identity function), '*' (multiplication versus 
> dereferencing).
> 
> If you only allow _unexpected_ expressions, as you suggest, that would 
> mean always choosing the first alternative above. That would mean you'd 
> have to disambiguate the unary versions of those operators by placing 
> them in parentheses: "foo 1 (-2)" instead of the initial example.
> But that leaves another ambiguity: what about "foo x (-2)"? That would 
> translate to foo.opSeq(x(-2)). I don't think this one can be resolved, 
> even placing parentheses around x doesn't work. For example, if x is a 
> delegate, the expression would mean the same thing with or without 
> parentheses around it, so there would be no way to call Foo.opSeq(void 
> delegate(int), int) except explicitly.
> 
> Besides, if you're going to place parentheses around all the operands 
> you might as well overload opCall and be done with it, without any 
> syntax extensions or added ambiguity at all.

Good points.  I'll ponder 'em.



More information about the Digitalmars-d mailing list