I've seen Eli's example of static variables on Stackoverflow, but I still need help.<div><br></div><div>I've created a working sieve and now I want to wrap it in a manner that save primes to be used later.</div>
<div><br></div><div>This is what I tried:</div><div><br></div><div><div>; wrapper function for sieve</div><div>(define (primes-from-to start end)</div><div> (let ([lastend 0] [storedlst '()])</div><div> (lambda ()</div>
<div> (cond [(= lastend 0) (set! storedlst (primes-to end))]</div><div> [(= lastend start) (set! storedlst (sieve (append storedlst (interval-list start end))))]</div><div> [(< lastend end) (primes-from-to lastend end)])</div>
<div> </div><div> ; storedlst now has all the primes needed</div><div> (set! lastend end) </div><div> (filter (lambda (v) (if (and (>= v start) (<= v end)) #t #f)) storedlst)</div><div> )))</div></div>
<div><br></div><div>It works, but I can't get any speed advantages as I simply don't know how to syntactically vary start and end and save lastend and storedlst.</div><div><br></div><div>(define a (prime-from-to 100 200)) is not useful when I want to later call (a 50 70).</div>
<div><br></div><div>I read the manual about all the define* functions but really nothing seems to fit, what am I missing?</div><div><br></div><div>Thanks,</div><div>-joe</div>