From 9cf86f51ee4dd078afadc45b8eb253bf28cf5241 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 7 Jul 2023 15:10:11 +0200 Subject: triangles --- shared/sicp-stream.rkt | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'shared') diff --git a/shared/sicp-stream.rkt b/shared/sicp-stream.rkt index e7a28d0..c695df7 100644 --- a/shared/sicp-stream.rkt +++ b/shared/sicp-stream.rkt @@ -9,6 +9,7 @@ display-line show display-stream + display-stream-until stream-ref stream-for-each stream-enumerate-interval @@ -27,6 +28,12 @@ (define (display-line x) (newline) (display x)) (define (show x) (display-line x) x) (define (display-stream s) (stream-for-each display-line s)) +(define (display-stream-until s until) + (cond ((< until 0) 'done) + ((stream-null? s) 'done) + (else (begin + (display-line (stream-car s)) + (display-stream-until (stream-cdr s) (- until 1)))))) (define (stream-ref s n) (if (= n 0) -- cgit v1.2.3