[racket] Out of memory
Hello,
in this racket:
Welcome to DrRacket, version 5.1.0.4--2011-03-26(fe75ed9/a) [3m].
Language: racket [custom]; memory limit: 128 MB.
(windows XP)
this program:
#lang racket
(define (test n exp)
(let ((v (make-vector n)))
(for ((i (in-range n)))
(vector-set! v i (expt (random) exp)))
(let sum ((i 0) (all 0.0) (pos 0.0) (neg 0.0))
(if (= i n)
(values all (+ pos neg))
(let ((item (vector-ref v i)))
(if (positive? item)
(sum (+ i 1) (+ all item) (+ pos item) neg)
(sum (+ i 1) (+ all item) pos (+ neg item))))))))
(test 10000000 -1)
sometimes signals an out of memory, and sometimes it runs to completion.
The cheching or unchecking of 'Debugging and profiling' and 'Preserve
stacktrace'
does not change this.
The function looks fine to me. So, what is the problem?
Thanks!
P.