[racket] Space safety in lazy

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Feb 19 08:50:07 EST 2012

Oops --- I should have tried that program more carefully.

The problem seems to be with `or'. If I change to `if', then the
example runs as intended:

 (define (has-negative? l)
   (if (negative? (car l))
       #t
       (has-negative? (rest l))))

The `or' from `lazy' effectively adds a `!' around its last argument
when `or' is applied directly, and it shouldn't do that. (Another
repair is to get `or' as a value, since the function form treats its
last argument correctly.)


At Sun, 19 Feb 2012 04:02:58 -0200, Rodolfo Carvalho wrote:
> I was reading Matthew Flatt's slides [1] and tried out an example using
> #lang lazy that IIUC should run "forever":
> 
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang lazy
> 
> (define (list-from n)
>   (cons n (list-from (add1 n))))
> 
> (define (has-negative? l)
>   (or (negative? (car l))
>       (has-negative? (rest l))))
> 
> (has-negative? (list-from 0))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> 
> However, after a minute or so it gives an out of memory error.
> DrRacket is set to use up to 256 MB, and even if I raise the limit to 512
> MB, eventually I get:
> 
> "The evaluation thread is no longer running, so no evaluation can take
> place until the next execution.
> The program ran out of memory."
> 
> Is it expected to happen? Why?
> 
> 
> 
> Thanks,
> 
> Rodolfo Carvalho
> 
> 
> [1] http://www.eng.utah.edu/~cs6510/space.pdf
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.