diff --git a/pkgs/racket-doc/scribblings/reference/sequences.scrbl b/pkgs/racket-doc/scribblings/reference/sequences.scrbl index 9f88fd2ec5..2d5477da17 100644 --- a/pkgs/racket-doc/scribblings/reference/sequences.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sequences.scrbl @@ -1073,8 +1073,8 @@ stream, but plain lists can be used as streams, and functions such as @racket[empty-stream]. } -@defform[(stream* expr ...)]{ - A shorthand for nested @racket[stream-cons]es, but the final @racket[expr] +@defform[(stream* expr ... rest-expr)]{ + A shorthand for nested @racket[stream-cons]es, but the @racket[rest-expr] must be a stream, and it is used as the rest of the stream instead of @racket[empty-stream]. Similar to @racket[list*] but for streams. diff --git a/pkgs/racket-test-core/tests/racket/stream.rktl b/pkgs/racket-test-core/tests/racket/stream.rktl index 525d3fc35f..d4e3eefa59 100644 --- a/pkgs/racket-test-core/tests/racket/stream.rktl +++ b/pkgs/racket-test-core/tests/racket/stream.rktl @@ -35,10 +35,14 @@ (test 4 stream-ref one-to-four 3) (test 2 'stream (stream-length (stream 1 (/ 0)))) (test 'a 'stream (stream-first (stream 'a (/ 0)))) +(test 1 'stream* (stream-first (stream* (stream 1)))) (test 2 'stream* (stream-length (stream* 1 (stream (/ 0))))) (test 'a 'stream* (stream-first (stream* 'a (stream (/ 0))))) (test 4 'stream* (stream-length (stream* 'a 'b 'c (stream (/ 0))))) (test 'c 'stream* (stream-first (stream-rest (stream-rest (stream* 'a 'b 'c (stream (/ 0))))))) +(err/rt-test (stream* 2) exn:fail:contract? "stream*") +(test #true 'stream* (stream? (stream* 1 0))) +(err/rt-test (stream-length (stream* 1 2)) exn:fail:contract? "stream*") ;; make sure stream operations work on lists (test #t stream-empty? '()) diff --git a/racket/collects/racket/stream.rkt b/racket/collects/racket/stream.rkt index a176f38e4a..f89cdabbcc 100644 --- a/racket/collects/racket/stream.rkt +++ b/racket/collects/racket/stream.rkt @@ -70,11 +70,16 @@ (define-syntax stream* (syntax-rules () - [(_ hd tl) - (stream-cons hd tl)] + [(_ tl) + (assert-stream? 'stream* tl)] [(_ hd tl ...) (stream-cons hd (stream* tl ...))])) +(define (assert-stream? who st) + (if (stream? st) + st + (raise-argument-error who "stream?" st))) + (define (stream->list s) (for/list ([v (in-stream s)]) v))