<div class="gmail_quote">Thanks, Matthew.<br><br><br>On Sun, Feb 19, 2012 at 11:50, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Oops --- I should have tried that program more carefully.<br>
<br>
The problem seems to be with `or'. If I change to `if', then the<br>
example runs as intended:<br>
<br>
(define (has-negative? l)<br>
(if (negative? (car l))<br>
#t<br>
(has-negative? (rest l))))<br>
<br>
The `or' from `lazy' effectively adds a `!' around its last argument<br>
when `or' is applied directly, and it shouldn't do that.</blockquote><div><br><br>Using `if' instead of `or' works.<br><br>But I don't understand when/why the force `!' is introduced or not.<br>For example, if I add a `set!' above the `if' expression, the program will run out of memory:<br>
<br>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>#lang lazy<br><br>(define (list-from n)<br> (cons n (list-from (add1 n))))<br><br>(define last-time-ms (current-inexact-milliseconds))<br>
<br>(define (has-negative? l)<br> (set! last-time-ms (current-inexact-milliseconds))<br> (if (negative? (car l))<br> #t<br> (has-negative? (rest l))))<br><br>(has-negative? (list-from 0)) ;; runs out of memory after a while<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br><br><br>How to reason about the "laziness" of the program?<br><br><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
(Another<br>
repair is to get `or' as a value, since the function form treats its<br>
last argument correctly.)<br></blockquote><div><br><br>I didn't understand the above. What does it mean to get `or' as a value?</div></div><br>