On Mon, Jun 22, 2009 at 04:59:07PM +0900, hojung yoon wrote: > from S03: > http://perlcabal.org/syn/S03.html#Conditional_operator_precedence > > : It is a syntax error to use an operator in the middle part that binds > looser in precedence, such as =. > > : my $x; > : hmm() ?? $x = 1 !! $x = 2; # ERROR > : hmm() ?? ($x = 1) !! ($x = 2); # works
This seems like something that is eligible for DWIMery. If the tokenizer were to automatically turn "??" and "!!" into "?? (" and ") !!", it would permit such constructions. This pair of operators should be acting like a bracketing pair, and not be especially susceptible to issues of precedence - it is only the expressions before the ?? and after the !! that should be affected by the precedence of the ??!! operator, any expression in between them should be allowed. (Rather than inserting imaginary parens, it can be done by treating the precedence of ?? as extremely low when compared to operators to its right, e.g. -1; and the precedence of !! as even lower (e.g. -2) when compared to operators on its left. Operators outside of the ?? ... !! area are compared using the official precedence of the ??!! operators. (Way back in compiler construction course I did a similar sort of thing to allow assignment to be put into the middle of an expression without requiring parens to bind the lvalue. (E.g. i=10*j=l+m was parsed as i=10*(j=l+m) with assignment being high precedence over operators to its left and low precedence to operators on its right.)