Re: [racket-dev] Need a clarification on the implementation of stream-map
And thus, the type of stream-map is NOT stream-map : (a - b) (stream a) - (stream b) but stream-map : (a b c ... - d e f ...) (stream a b c ...) - (stream d e f ...) Jay On Sun, Jul 8, 2012 at 8:00 AM, Robby Findler ro...@eecs.northwestern.edu wrote: 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. Robby On Sun, Jul 8, 2012 at 6:25 AM, Daniel King dank...@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 _ Racket Developers list: http://lists.racket-lang.org/dev -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Need a clarification on the implementation of stream-map
Sorry, I accidentally sent this off the mailing list and accidentally switched emails. Eli, I don't see any trace of multiple valued `stream's in racket/stream. Can you confirm or deny their existence? On Tue, Jul 10, 2012 at 11:13 PM, Jay McCarthy jay.mccar...@gmail.com wrote: Eli wrote racket/stream based on racket/sequence which I wrote. You'll have to ask him whether he added support for multiple-value sequences and how to get them. Jay On Tue, Jul 10, 2012 at 4:15 PM, Daniel King dank...@cern.ch wrote: On Tue, Jul 10, 2012 at 9:06 PM, Jay McCarthy jay.mccar...@gmail.com wrote: Your example is one-valued stream not a three-valued stream. How does one produce a stream with more than one-value? I assume that if there are no multi-valued streams then there is no need for the aforementioned snippet in the implementation of `stream-map'. -- Dan King Northeastern University -- Jay McCarthy j...@cs.byu.edu Assistant Professor / Brigham Young University http://faculty.cs.byu.edu/~jay The glory of God is Intelligence - DC 93 -- Dan King College of Computer and Information Science Northeastern University _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Need a clarification on the implementation of stream-map
No, I didn't write `racket/stream' -- Matthew did it based on the stream srfi. This came up not too long ago, and I sent a question about it here: http://lists.racket-lang.org/dev/archive/2012-June/009612.html Since there were no replies, I meant to remove it but didn't get to it. I'll push it out now. 6 hours ago, Daniel King wrote: Sorry, I accidentally sent this off the mailing list and accidentally switched emails. Eli, I don't see any trace of multiple valued `stream's in racket/stream. Can you confirm or deny their existence? On Tue, Jul 10, 2012 at 11:13 PM, Jay McCarthy jay.mccar...@gmail.com wrote: Eli wrote racket/stream based on racket/sequence which I wrote. You'll have to ask him whether he added support for multiple-value sequences and how to get them. -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Need a clarification on the implementation of stream-map
On Jul 8, 2012, at 7:25 AM, Daniel King wrote: (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)) On a related note, the above kind of checks should really become real contracts. -- Matthias (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)))]))) _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] Need a clarification on the implementation of stream-map
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. Robby On Sun, Jul 8, 2012 at 6:25 AM, Daniel King dank...@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 _ Racket Developers list: http://lists.racket-lang.org/dev