On Thu, Mar 20, 2008 at 1:09 PM, Doug McNutt <[EMAIL PROTECTED]> wrote: > Don't even think about parsing = -$x**2; so that it returns a positive > result.
Okay, going way off on a tangent here, but I don't think the Perl interpretation is quite as obviously correct as you think it is; there's a reason the perlsyn page describes it as possibly surprising. Especially if you use a literal instead of a variable, in which case the '-' might be considered part of the literal token in some languages and preempt operator precedence altogether. In any case, the decision is far from unanimous. Fortran, the original source of the ** operator, agrees with Perl on this front; but COBOL, if asked to COMPUTE the same expression, returns a positive result. ( I know, what do you expect from a business-oriented language...) Ada, AWK, Groovy, Haskell, LSL, Lua, Pascal, Python, Ruby, Scala, and Simula all agree that the result is negative. APL also agrees, and it's arguably the ultimate mathematician's language, but it also just evaluates right to left with no precedence levels. There are also languages like M[UMPS] that similarly lack precedence and just plow through left to right, which yields a positive answer here. Precedenceful languages that return a positive result include ALGOL-68, AppleScript, bash/ksh/zsh (let-arithmetic), bc(1), Eiffel, and SNOBOL. SmallTalk has no unary -, but "0 - x raisedTo: 2" yields a positive answer. The various Basic implementations disagree with each other; Visual Basic (including VB.NET) and LibertyBASIC say it's positive, while Chipmunk says negative. Going back in time to 8-bit days, the BASICs on Commodore, TI, Sinclair, and TRS-80 (model 1 level 2) machines return a negative result, while Apple and Atari return a positive one. I find it particularly interesting that not even all of the BASICs from the same codebase (Microsoft's original Altair release) agree with each other... We now return you to your regularly scheduled Perl 6 mailing list, already in progress. -- Mark J. Reed <[EMAIL PROTECTED]>