[racket-dev] Need a clarification on the implementation of stream-map

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Jul 8 08:00:48 EDT 2012

I'm not sure about the rationale behind the design of stream-map, but
"any" as a result contract for a function indicates it may return
multiple values (in the range of a function "any" is a special
keyword). "any/c" is a contract for a single value.


On Sun, Jul 8, 2012 at 6:25 AM, Daniel King <danking at ccs.neu.edu> wrote:
> Question 0:
> In collects/racket/stream.rkt, `stream-map' is defined as:
>   (define (stream-map f s)
>     (unless (procedure? f) (raise-argument-error 'stream-map "procedure?" f))
>     (unless (stream? s) (raise-argument-error 'stream-map "stream?" s))
>     (let loop ([s s])
>       (cond
>        [(stream-empty? s) empty-stream]
>        [else (stream-cons (call-with-values (lambda () (stream-first s)) f)
>                           (loop (stream-rest s)))])))
> I don't understand the difference between:
>   (call-with-values (lambda () (stream-first s)) f)
> and
>   (f (stream-first s))
> because the contract for `stream-first' is:
>   (stream-first s) → any
>   s : (and/c stream? (not/c stream-empty?))
> Which seems to me to just return a single value. I was taking a second look at
> my changes to `stream-map' which add support for multiple streams. I noticed
> this unusual snippet as I rebased onto the latest version of plt/master.
> Question 1:
> Would it make more sense to simply update all the sequence procedures to handle
> multiple sequences? Is there a circumstance where it doesn't make sense to
> handle multiple sequences in a sequence procedure such as `sequence-map'?
> I figure that the sequence procedures don't support multiple sequences is just
> lack of interest. Do most people just use the `for' macros in these cases?
> --
> Dan King
> College of Computer and Information Science
> Northeastern University
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.