[gambit-list] Space leak or bad gc parameters?
denis.prog at hotmail.com
Sun May 17 01:13:45 EDT 2015
I have just pasted it in gsi -:s so it should be ok, please have a look. I have also tried chibi and chicken and only scheme48 was able to achieve it with less than 60MB (although it was rather slow). Please tell me if you would like to see the more crude version with delay as a thunk.
;; definitions : similar to the matching functions for lists(define-syntax cons-stream (syntax-rules () ((cons-stream a b) (cons a (delay b)))))
(define empty-stream '())(define stream-null? null?)
(define (stream-car stream) (car stream))
(define (stream-cdr stream) (force (cdr stream)))
(define (stream-filter pred? stream) (cond ((stream-null? stream) empty-stream) ((pred? (stream-car stream)) (cons-stream (stream-car stream) (stream-filter pred? (stream-cdr stream)))) (else (stream-filter pred? (stream-cdr stream)))))
(define (stream-ref stream n . default) (let loop ((s stream) (i n)) (cond ((stream-null? s) (and (pair? default) (car default))) ((<= i 0) (stream-car s)) (else (loop (stream-cdr s) (- i 1))))))
;; an infinite stream of ints(define (int-from n) (cons-stream n (int-from (+ n 1))))
(define (erastho stream) (let ((n (stream-car stream))) (cons-stream n (erastho (stream-filter (lambda (i) (not (= (modulo i n) 0))) (stream-cdr stream))))))
;;getting the 50th prime number,(stream-ref (erastho (int-from 2)) 50);;getting the 10000th prime number(stream-ref (erastho (int-from 2)) 10000)
> CC: gambit-list at iro.umontreal.ca; lucier at math.purdue.edu
> From: lucier at math.purdue.edu
> Subject: Re: [gambit-list] Space leak or bad gc parameters?
> Date: Sat, 16 May 2015 19:29:50 -0400
> To: denis.prog at hotmail.com
> Show us the code.
> Ps: Sorry about my email screw ups.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gambit-list