[racket] Out of memory

From: Pierpaolo Bernardi (olopierpa at gmail.com)
Date: Mon Apr 4 10:04:53 EDT 2011


in this racket:

Welcome to DrRacket, version [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
does not change this.

The function looks fine to me. So, what is the problem?



Posted on the users mailing list.