From d7335dbfef0978c2ab4ff0ecc1266aa4dfac531c Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Tue, 30 Sep 2003 04:22:59 +0000
Subject: [PATCH] Implement STREAM-LAST-PAIR.

---
 v7/src/runtime/runtime.pkg |  3 ++-
 v7/src/runtime/stream.scm  | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg
index 2dd9df620..b4f0aec38 100644
--- a/v7/src/runtime/runtime.pkg
+++ b/v7/src/runtime/runtime.pkg
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: runtime.pkg,v 14.460 2003/09/30 03:39:10 cph Exp $
+$Id: runtime.pkg,v 14.461 2003/09/30 04:22:52 cph Exp $
 
 Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
 Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
@@ -3783,6 +3783,7 @@ USA.
 	  stream-first
 	  stream-for-each
 	  stream-head
+	  stream-last-pair
 	  stream-length
 	  stream-map
 	  stream-null?
diff --git a/v7/src/runtime/stream.scm b/v7/src/runtime/stream.scm
index 3b3aecf34..2a0c6d50d 100644
--- a/v7/src/runtime/stream.scm
+++ b/v7/src/runtime/stream.scm
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: stream.scm,v 14.17 2003/09/30 04:16:45 cph Exp $
+$Id: stream.scm,v 14.18 2003/09/30 04:22:59 cph Exp $
 
 Copyright 1986,1987,1988,1989,1992,1995 Massachusetts Institute of Technology
 Copyright 1998,2003 Massachusetts Institute of Technology
@@ -89,6 +89,20 @@ USA.
 	      (error:bad-range-argument index 'STREAM-TAIL))
 	  (loop (force (cdr stream)) (- index 1)))
 	stream)))
+
+(define (stream-last-pair stream)
+  (if (not (stream-pair? stream))
+      (if (null? stream)
+	  (error:bad-range-argument stream 'STREAM-LAST-PAIR)
+	  (error:illegal-stream-element stream 'STREAM-LAST-PAIR 0)))
+  (let loop ((stream stream))
+    (let ((next (force (cdr stream))))
+      (if (stream-pair? next)
+	  (loop next)
+	  (begin
+	    (if (not (null? stream))
+		(error:illegal-stream-element stream 'STREAM-LAST-PAIR 0))
+	    stream)))))
 
 (define (stream-map procedure stream . streams)
   (cond ((pair? streams)
-- 
2.25.1