[racket] static variables question

From: Gary Baumgartner (gfb at cs.toronto.edu)
Date: Sat Feb 18 14:42:37 EST 2012

On Sat, Feb 18, 2012 at 12:51:23AM -0800, Joe Gilray wrote:
>    OK, I read some more and played around and got the behavior I wanted as
>    follows:
> 
>    (define primes-from-to
>      (let ([lastend 0] [storedlst '()])

This means that these variables are created once, while creating the
 value for 'prime-from-to' [which ends up being a function].
 Your original was impicitly

  (define primes-from-to
    (lambda (start end)
      (let ([lastend 0] [storedlst '()])
        <etc>)))

 which meant those variable would be created locally each time the lambda
 [via 'primes-from-to'] was called.

>        (lambda (start end)
[...]

>        (filter (lambda (v) (if (and (>= v start) (<= v end)) #t #f))
>    storedlst)
>        )))
[...]

Consider just (lambda (v) (and (>= v start) (<= v end))) --- no 'if'.

For symmetry put 'v' in order between start, end: (and (<= start v) (<= v end)) .
 That inspires: (<= start v end) .

Posted on the users mailing list.