<< Previous exercise (3.50)
| Index |
Next exercise (3.52) >>
(define (show x)
(define x (stream-map show (stream-enumerate-interval 0 10)))
(stream-ref x 5)
(stream-ref x 7)
I get a different result. On Racket, with all of the procedures implemented exactly as specified in the book, I get:
racket@> (define x
(stream-enumerate-interval 0 10)))
10racket@> (stream-ref x 5)
racket@> (stream-ref x 7)
The only thing which could possibly account for this discrepancy is a mistake in my implementation of delay, but it looks fine to me?
(define delay (lambda (proc) (memo-proc (lambda () proc))))
Any idea why I get different results?
EDIT: After solving the next exercise and looking at other solutions, it seems like the evaluations aren't actually being delayed, could it be some aspect of Racket's implementation which is preventing it from working?
master, the "delay" implementation that you have provided doesn't prevent the expression from being evaluated while you call the delay function.
While making the call (delay <exp>) : How do you convey to the interpreter that the exp should not be evaluated before calling the delay function.
The book mentions that delay is equivalent to the implementation(not equal) that you have provided as it requires a special syntax rule that prevents execution while calling. I guess that is why in the book they said they are equivalent but they never said they are equal. Remove your custom implementation of delay and use the language provided and you will see the expected behavior.