[plt-scheme] Dead lock using map-stream?

From: G. Saini (gsaini at u.washington.edu)
Date: Sun Nov 23 13:32:29 EST 2003

Oops, you're right this makes no sense. The plus operator, of course,
requires at least two operands. Hence I tried the incrementor operator
(1+). So instead of +, we use 1+:

(map-stream 1+ (enumerate-interval 0 10))

The result still seems to be stalled. It is:
;Value 34: (1.#[promise])

My suspicion, after a good night's rest of course, is that this is the
way it is supposed to be since no tail has been evaluated yet. Hence
I wrote a simple printout procedure to force the evaluation:

(define (show-all stream)
   (if (empty-stream? stream)
        the-empty-stream
       (begin (format #t " \n ~A \n" (head stream))
              (show-all (tail stream)))))

Now the following call will print out the incremented list properly:

(show-all (map-stream 1+ (enumerate-interval 0 10)))

I conclude then that the novice lesson for me is that the full
will ONLY be evaluated when there is an explict call to tail
without being in a cons-stream.



On Sun, 23 Nov 2003, Dor Kleiman wrote:

> First of all, what good would that thing do?
> map-stream calls proc for each element of the stream, or in other words, calls (+ 0), (+ 1), etc. and streams them.
> Second, does (enumerate-interval 0 10) work?
>
>
> 	-----Original Message-----
> 	From: Gurpreet S. Saini [mailto:gsaini at u.washington.edu]
> 	Sent: א 23/11/2003 05:08
> 	To: plt-scheme at list.cs.brown.edu
> 	Cc:
> 	Subject: [plt-scheme] Dead lock using map-stream?
>
>
>
> 	  For list-related administrative tasks:
> 	  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 	[Note that both of definitions come from chapter 3 of
> 	the first edition of SICP]
>
> 	Consider
>
> 	1. the following defintions:
>
> 	(define the-empty-stream '())
>
> 	(define (enumerate-interval low high)
> 	        (if (> low high)
> 	            the-empty-stream
> 	            (cons-stream low
> 	                        (enumerate-interval (+ low 1) high))))
>
> 	(define (map-stream proc stream)
> 	    (if (empty-stream? stream)
> 	         the-empty-stream
> 	         (cons-stream (proc (head stream))
> 	                      (map-stream proc (tail stream)))))
>
> 	2. And the following call:
>
> 	(map-stream + (enumerate-interval 0 10))
>
> 	Right now this call is stalled. It looks to me like
> 	this is supposed to happen. This is because both enumerate-interval and
> 	map-stream's call to tail is in a cons-stream.
>
>
> 	thanks
> 	--Gurp
>
>
>
>
>
>
>
>
>
>
>
>


Posted on the users mailing list.