in reply to c-style for loop versus list for loop, and bigint

Because the range operator (integer iterator) is not affected by bigint. You can also do:

use strict; use warnings; use bigint; my $answer = 0; for my $i ( map 0+$_,1 .. 999 ) { print "$i: $answer\n"; $answer += $i ** $i; } $answer %= 10 ** 10; print "$answer\n";

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: c-style for loop versus list for loop, and bigint
by AR (Friar) on May 19, 2011 at 20:45 UTC

    Because the range operator (integer iterator) is not affected by bigint

    Is that intentional?

      Is that intentional?

      Yes. The range operator is intended to be efficient for the majority of every day use cases.

      As you've already discovered, if you need to iterate infinite precision integers, you can easily use the c-style alternative.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        > The range operator is intended to be efficient for the majority of every day use cases.

        oh please come on!

        Don't you think use bigint may indicate a non everyday use case?

        Neither bigint nor Math::BigInt mention this problem or even the range operator.

        And maybe it's even possible to fix by overloading ".." in UNIVERSAL.¹

        Cheers Rolf

        UPDATE:

        1) seems like overloading the range operator was never intended: Overloadable Operations

      >Is that intentional?

      let's say it's historical. :)

      I suppose the range iterator is just older than bigint.

      I wouldn't be surprised if bigint is just just a hack to overload scalars with objects and the effect of iterating over a range was forgotten.

      Cheers Rolf

        Actually, I'm fairly certain that the conversion of the range operator from a list generator to an iterator happened long after bigint was available.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.