From: Joe Marshall Date: Sat, 16 Jan 2016 23:53:58 +0000 (-0800) Subject: Don't blow out the stack in STREAM->LIST. X-Git-Tag: mit-scheme-pucked-9.2.12~373^2~8 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=2cc6c470d252fd1f30b1f3697615c667d6d6b8f6;p=mit-scheme.git Don't blow out the stack in STREAM->LIST. --- diff --git a/src/runtime/stream.scm b/src/runtime/stream.scm index 6c49ebc35..e0a0e306e 100644 --- a/src/runtime/stream.scm +++ b/src/runtime/stream.scm @@ -265,13 +265,11 @@ USA. '()))) (define (stream->list stream) - (if (stream-pair? stream) - (cons (car stream) - (stream->list (force (cdr stream)))) - (begin - (if (not (null? stream)) - (error:illegal-stream-element stream 'STREAM->LIST 0)) - '()))) + (let loop ((s stream) + (elements '())) + (cond ((stream-pair? tail) (loop (tail s) (cons (head s) elements))) + ((null? s) (reverse elements)) + (else (error:illegal-stream-element stream 'STREAM->LIST 0))))) (define prime-numbers-stream)