From: jmarshall Date: Sat, 16 Jan 2016 04:50:27 +0000 (-0800) Subject: Add STREAM-LAST and STREAM-TRUNCATE. Fixed a typo. X-Git-Tag: mit-scheme-pucked-9.2.12~373^2~10 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3400af94611839efd710d191f983be6d05df86da;p=mit-scheme.git Add STREAM-LAST and STREAM-TRUNCATE. Fixed a typo. --- diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 4a9bdf35a..10a558c8c 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -4606,6 +4606,7 @@ USA. stream-first stream-for-each stream-head + stream-last stream-last-pair stream-length stream-map @@ -4614,6 +4615,7 @@ USA. stream-ref stream-rest stream-tail + stream-truncate stream-write tail the-empty-stream) diff --git a/src/runtime/stream.scm b/src/runtime/stream.scm index 31da2be30..6c49ebc35 100644 --- a/src/runtime/stream.scm +++ b/src/runtime/stream.scm @@ -90,6 +90,9 @@ USA. (loop (force (cdr stream)) (- index 1))) stream))) +(define (stream-last stream) + (stream-car (stream-last-pair stream))) + (define (stream-last-pair stream) (if (not (stream-pair? stream)) (if (null? stream) @@ -100,7 +103,7 @@ USA. (if (stream-pair? next) (loop next) (begin - (if (not (null? stream)) + (if (not (null? next)) (error:illegal-stream-element stream 'STREAM-LAST-PAIR 0)) stream))))) @@ -223,6 +226,17 @@ USA. (error:illegal-stream-element stream 'STREAM-FILTER 1)) '()))) +(define (stream-truncate stream predicate) + (if (stream-pair? stream) + (if (predicate (head stream)) + the-empty-stream + (cons-stream (head stream) + (stream-truncate (tail stream) predicate))) + (begin + (if (not (null? stream)) + (error:illegal-stream-element stream 'STREAM-TRUNCATE 1)) + '()))) + (define (stream-write stream #!optional port) (let ((port (if (default-object? port)