On Mon, Aug 25, 2008 at 04:10:28PM +0200, Moritz Lenz wrote:
> > The attached program, primes.p6 seems to work correctly, except that after
> > processing the numbers from 1-6000+, it segfaults
> > Here are the last few lines.  Note that it had already output the first two
> > chunks, and so it was between 6400 and 10000 when it segfaulted.
> > [...]
> > 6329 6337 6343 6353 6359 6361 6367 6373 6379 6389 6397 6421 6427 6449 6451
> > 6469 6473 6481Segmentation fault
> 
> When you s/print/say/ you see that it gets as far as 9949 (no line
> buffering any more) before the segfault, at least on my machine.

I get the same results on my machine.  If you also change the outer
loop to start at 5000 instead of 1, then it gets all the way through
to the end with no difficulty:

    $ cat primes.p6
    sub prime(Int $n) {
            return 0 if $n % 2 == 0;
            my $limit = sqrt($n);
            loop (my $i=3; $i<$limit; $i+=2) {
                    if $n % $i == 0 { return 0; }
            }
            return 1;
    }
    
    loop(my $n=5000; $n<=10000; $n++) {
            if prime($n) { say $n; }
    }
    say "done";
    $ ./parrot perl6.pbc primes.p6
    5003
    5009
    5011
    ...
    9931
    9941
    9949
    9967
    9973
    done
    $

So, I suspect that the difficulty is internal to Parrot somehow,
and not specific to Rakudo.

I'm hoping to get the options in place to have Rakudo generate
standalone PIR in the next day or so -- perhaps that will help
with Parrot debugging.

Pm

Reply via email to