On Mon, May 16, 2011 at 03:45:08PM -0400, Parrot Raiser wrote:
> The following piece of trivial code, (drastically simplified from an
> example I was trying to convert), produces different results (3rd
> line) under Perl 5 and Perl 6. (Saved as t_f_int2)
> 
>     print sqrt (1.5 * 1) ;
> print "\n";
>     print    ((1 / 2.7) ** 1);
> print "\n";
> 
>     print sqrt (1.5 * 1) *
>         ((1 / 2.7) ** 1);
> 
> print "\n";
> [...]
> $>perl6 t_f_int2
> 1.22474487139159
> 0.37037037037037
> 0.74535599249993
> 
> Have I found a bug or merely revealed my ignorance of a change in
> precedence somewhere?

You've found the difference in how Perl 5 and Perl 6 handles 
whitespace+parentheses following a function name.  In Perl 5, only
the parenthesized part is passed to C<sqrt>; in Perl 6, the entire
expression will be passed as an argument to the sqrt listop.

Removing the space between "sqrt" and the parenthesized part will
cause sqrt to act like a normal function on just the value in the
parentheses instead of the full expression:

  $ ./perl6 -e 'say sqrt (1.5 * 1) * ((1 / 2.7) ** 1);'
  0.74535599249993
  $ ./perl6 -e 'say sqrt(1.5 * 1) * ((1 / 2.7) ** 1);'
  0.453609211626514

In general, a paren immediately following an identifier is treated
as a function call, while whitespace indicates it's a listop or some
other construct.

Pm

Reply via email to