in reply to Re^2: order of arguments evaluated
in thread order of arguments evaluated

$i += $i++ - ++$i; Can we agree that that expression is dog ugly? What exactly should the value of $i be after evaluation? Why? Think about 0**0. What should that value be? You can devise arguments that it could be either 0 or 1 (i.e. $anything**0==1 but 0*$anything==0). Assigning meaning to the original expression can be done, but ugly expressions like that should be avoided in the first place. Perl's designers decided that it would be hard to prevent people from writing ugly code, but they're going to wash their hands of the whole enterprise by saying "bah, if you want to shoot yourself in the foot, feel free. Just be aware that we aren't making promises that your program will work properly in the future."

Replies are listed 'Best First'.
Re: 0**0
by Anonymous Monk on May 31, 2005 at 02:45 UTC
    Since when is 0**0 undefined or in question? True, zero times anything is zero, but 0**0 is the product of zero numbers. Since there are no numbers to multiply, there is no 0 to multiply by anything to apply that rule.

    Multiplying zero numbers together must give the identity for multiplication (that's 1). Just like adding zero numbers together is the identity for addition (that's 0).

    </rant> .. anyway, your point is fine, but bad example ;)

      sci.math FAQ: What is 0^0?...
      According to some Calculus textbooks, 0^0 is an ``indeterminate form''. When evaluating a limit of the form 0^0, then you need to know that limits of that form are called ``indeterminate forms'', and that you need to use a special technique such as L'Hopital's rule to evaluate them. Otherwise, 0^0 = 1 seems to be the most useful choice for 0^0. This convention allows us to extend definitions in different areas of mathematics that otherwise would require treating 0 as a special case. Notice that 0^0 is a discontinuity of the function x^y. More importantly, keep in mind that the value of a function and its limit need not be the same thing, and functions need not be continous, if that serves a purpose (see Dirac's delta). This means that depending on the context where 0^0 occurs, you might wish to substitute it with 1, indeterminate or undefined/nonexistent...

        Perhaps I'm missing the point - could you elaborate further how that relates to Perl?

        Think about 0**0. What should that value be? You can devise arguments that it could be either 0 or 1 (i.e. $anything**0==1 but 0*$anything==0)

        0**0 (in perl) equals 0^0 (in exponent notation) equals 1

        Any number computed to the exponent of 0 is 1. Perl behaves this way.

        if (eval(0**0)){print "JAPH\n";}

        The math article noted would seem to support that assertion as well. While there are speculative comments to the contrary towards the beginning of the article, the citations noted in following instead support this idea again.

        How is this ugly? It seems to be clearly defined. Is that the issue? Would you prefer to be able to configure it depending on the job? Is this like trying to ban guns to keep people from shooting themselves in the foot or are we offering them telescopic sighting mechanisms so they can shoot only the offending toe?



        Wait! This isn't a Parachute, this is a Backpack!