Does anyone have a faster technique to build a list between a start and stop value?
I made the straight forward
[code]
(define (mkrng min max)
(cond
((< max min) '())
(else(cons max (mkrng min (- max 1)))))) [\code]
But it is really slow for my application which needs lists of tens of millions of numbers
Name:
Anonymous2012-02-11 16:00
One way is to use delay and force.
(define (make-range x y)
(if (> x y)
'()
(cons x (delay (make-range (+ x 1) y)))))
This will return a pair of x and a "promise" to evaluate (make-range (+ x 1) y) later. You can evaluate it by calling (force (cdr range)), where range is the pair returned by make-range.
but here is an attempt at creating a lazy list in scheme...
;; a lazy cell consists of a pair (x . xs)
;; where x is an evaluated value that can be accessed,
;; and xs is a function that takes no arguments, that will generate
;; the next lazy cell.