add stream' to
racket/stream'
based on a pull request from Dan King
This commit is contained in:
parent
90acf8a36f
commit
7e666b4b45
|
@ -14,6 +14,7 @@
|
||||||
prop:stream
|
prop:stream
|
||||||
in-stream
|
in-stream
|
||||||
|
|
||||||
|
stream
|
||||||
stream->list
|
stream->list
|
||||||
stream-length
|
stream-length
|
||||||
stream-ref
|
stream-ref
|
||||||
|
@ -28,6 +29,13 @@
|
||||||
stream-add-between
|
stream-add-between
|
||||||
stream-count)
|
stream-count)
|
||||||
|
|
||||||
|
(define-syntax stream
|
||||||
|
(syntax-rules ()
|
||||||
|
((_)
|
||||||
|
empty-stream)
|
||||||
|
((_ hd tl ...)
|
||||||
|
(stream-cons hd (stream tl ...)))))
|
||||||
|
|
||||||
(define (stream->list s)
|
(define (stream->list s)
|
||||||
(for/list ([v (in-stream s)]) v))
|
(for/list ([v (in-stream s)]) v))
|
||||||
|
|
||||||
|
|
|
@ -595,6 +595,11 @@ The first element of the stream as produced by @racket[first-expr]
|
||||||
must be a single value. The @racket[rest-expr] must produce a stream
|
must be a single value. The @racket[rest-expr] must produce a stream
|
||||||
when it is evaluated, otherwise the @exnraise[exn:fail:contract?].}
|
when it is evaluated, otherwise the @exnraise[exn:fail:contract?].}
|
||||||
|
|
||||||
|
@defform[(stream expr ...)]{
|
||||||
|
|
||||||
|
A shorthand for nested @racket[stream-cons]es ending with
|
||||||
|
@racket[empty-stream].}
|
||||||
|
|
||||||
@defproc[(in-stream [s stream?]) sequence?]{
|
@defproc[(in-stream [s stream?]) sequence?]{
|
||||||
Returns a sequence that is equivalent to @racket[s].
|
Returns a sequence that is equivalent to @racket[s].
|
||||||
@speed[in-stream "streams"]}
|
@speed[in-stream "streams"]}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
(test #f stream? '#(1 2))
|
(test #f stream? '#(1 2))
|
||||||
|
|
||||||
(test 1 'stream-length (stream-length (stream-cons 1 empty-stream)))
|
(test 1 'stream-length (stream-length (stream-cons 1 empty-stream)))
|
||||||
|
(test 1 'stream-length (stream-length (stream 1)))
|
||||||
|
|
||||||
(define infinite-ones (stream-cons 1 infinite-ones))
|
(define infinite-ones (stream-cons 1 infinite-ones))
|
||||||
|
|
||||||
|
@ -27,4 +28,12 @@
|
||||||
(test "hello" stream-first (sequence->stream (in-producer (lambda () "hello") (void))))
|
(test "hello" stream-first (sequence->stream (in-producer (lambda () "hello") (void))))
|
||||||
(test 65 stream-first (sequence->stream (in-port read-byte (open-input-string "A"))))
|
(test 65 stream-first (sequence->stream (in-port read-byte (open-input-string "A"))))
|
||||||
|
|
||||||
|
(define one-to-four (stream 1 2 3 4))
|
||||||
|
(test 1 stream-first one-to-four)
|
||||||
|
(test 2 stream-ref one-to-four 1)
|
||||||
|
(test 3 stream-ref one-to-four 2)
|
||||||
|
(test 4 stream-ref one-to-four 3)
|
||||||
|
(test 2 'stream (stream-length (stream 1 (/ 0))))
|
||||||
|
(test 'a 'stream (stream-first (stream 'a (/ 0))))
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
|
@ -2,6 +2,7 @@ Version 5.2.0.5
|
||||||
Cross-module inlining of trivial functions, plus map, for-each,
|
Cross-module inlining of trivial functions, plus map, for-each,
|
||||||
andmap, and ormap; 'compiler-hint:cross-module-inline hint
|
andmap, and ormap; 'compiler-hint:cross-module-inline hint
|
||||||
compiler/zo-structs: added inline-variant
|
compiler/zo-structs: added inline-variant
|
||||||
|
racket/stream: added stream constructor
|
||||||
|
|
||||||
Version 5.2.0.4
|
Version 5.2.0.4
|
||||||
Regexps are `equal?' when they have the same source [byte] string
|
Regexps are `equal?' when they have the same source [byte] string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user