Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Perl 6 and performance

by kikuchiyo (Monk)
on Feb 09, 2012 at 19:32 UTC ( #952817=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl 6 and performance
in thread Perl 6 and performance

Thank you for the detailed answer. It indeed makes the cause of the problem clear.

For me, it's more natural to write a floating point constant one as 1.0, however, that doesn't work. And this won't even run:

time ./perl6 -e 'my $s; for 1..10000 {$s+=1./$_**2};say $s' ===SORRY!=== Unable to parse blockoid, couldn't find final '}' at line 2

I've also tried to explicitly declare the loop variable as a floating point:

./perl6 -e 'my $s;my Num $i;for 1..10000 -> $i {$s+=1/$i**2};say $s'

This has no effect, as can be seen from the following:

./perl6 -e 'my Num $s;my Num $i;for 1..10000 -> $i {$s+=1/$i**2};say $ +s' Type check failed in assignment to '$s'; expected 'Num' but got 'Rat' in method reify at src/gen/CORE.setting:4471 in method reify at src/gen/CORE.setting:4376 in method reify at src/gen/CORE.setting:4376 in method gimme at src/gen/CORE.setting:4740 in method eager at src/gen/CORE.setting:4715 in method eager at src/gen/CORE.setting:1028 in sub eager at src/gen/CORE.setting:5000

Does this mean that even though I declare $i as a Num, it's still an integer when used as a loop variable? Is it because the .. operator supplies integers?

P.S. I'm sad to see that perlmonks is slowly becoming more like reddit, where problems are met with rancorousness instead of being discussed on a technical level.

I admit that I posed the original question in a slightly more trollish way than necessary, and I apologize for the inconvenience I might have created. I didn't intend to denigrate the effort of the Perl 6 developers - an effort which is nothing short of heroic.

However, I do think that the problems with the current state of Perl 6 go way beyond the technical level, and pretending that these problems can be treated at the mere technical level is an attitude that does more harm than good on the long term.


Comment on Re^2: Perl 6 and performance
Select or Download Code
Re^3: Perl 6 and performance
by moritz (Cardinal) on Feb 09, 2012 at 19:59 UTC

    To clarify things, 1. is not a valid number in Perl 6. 1.0 is a Rat, 1e0 or 1.0e0 are Num.

    I've also tried to explicitly declare the loop variable as a floating point:

    There are two issues with it. The first is that you don't declare the loop variable to be a Num, but an outer variable of the same name. In -> $i { ... } the part between the arrow and the block is a signature, which declares a new variable. So it's like writing

    my Num $i; sub ($i) { # new $i here }

    A way to fix that is writing -> Num $i { }, but then you get a type check failure because 1..1000 indeed produces Ints, not Nums. So either you coerce to Num somewhere (for example $i.Num ** 2), or you write the range as 1e0 .. 1e3.

    I admit that I posed the original question in a slightly more trollish way than necessary, and I apologize for the inconvenience I might have created. I didn't intend to denigrate the effort of the Perl 6 developers - an effort which is nothing short of heroic.

    My side remark was more about _foo's trolling, not about your original question, which I think is 100% valid, and a good bug report at that. Sorry if that came out wrong on my part. User feedback like yours is what we need, and one of the reasons for making the star releases in the first place.

      To clarify things, 1. is not a valid number in Perl 6. 1.0 is a Rat, 1e0 or 1.0e0 are Num.

      This is news to me. In most languages 1.0 is the syntax used to denote floating point constants.

      ...I am aware that Perl 6 is not most languages, but for people coming from those languages, this feature will be somewhat surprising.

      A way to fix that is writing -> Num $i { }, but then you get a type check failure because 1..1000 indeed produces Ints, not Nums. So either you coerce to Num somewhere (for example $i.Num ** 2), or you write the range as 1e0 .. 1e3.
      Excellent. However:
      ./perl6 -e 'my Num $s;for 1e0..1e3 -> Num $i {$s+=1e0/$i**2};say $s' Nominal type check failed for parameter '$i'; expected Num but got Int + instead
      User feedback like yours is what we need, and one of the reasons for making the star releases in the first place.

      Glad to have been of help then. By the way, the performance increase is noticeable in the new release, and I guess it will only get better, and the effect of further optimizations will be compounded, as Rakudo itself is mostly written in Perl 6.

      About 1.6 orders of magnitude of performance increase down, 2.6 to get to the level of Perl 5, or 1.6 to overtake Ruby. :)

        ./perl6 -e 'my Num $s;for 1e0..1e3 -> Num $i {$s+=1e0/$i**2};say $s' Nominal type check failed for parameter '$i'; expected Num but got Int + instead

        Oops, that's a bug in Rakudo. I've opened a ticket for it. Now that's the second piece of valuable feedback you've given us. Thanks again.

        Update: I have fixed this bug, so the code with -> Num $i { ... } will work in the next release.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-12-23 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (135 votes), past polls