Added last-pair and tests

svn: r9422

original commit: 13c5e3812d252bab985f29210862308ae8623396
This commit is contained in:
Eli Barzilay 2008-04-23 13:20:05 +00:00
parent 821142782e
commit e523655315

View File

@ -1,5 +1,4 @@
#lang mzscheme
(module list mzscheme
;; The `first', etc. operations in this library ;; The `first', etc. operations in this library
;; work on pairs, not lists. ;; work on pairs, not lists.
@ -25,7 +24,8 @@
(only scheme/list (only scheme/list
cons? cons?
empty? empty?
empty)) empty
last-pair))
(provide first (provide first
second second
@ -109,12 +109,3 @@
(unless (pair? x) (unless (pair? x)
(raise-type-error 'rest "non-empty list" x)) (raise-type-error 'rest "non-empty list" x))
(cdr x)) (cdr x))
(define (last-pair l)
(if (pair? l)
(let loop ([l l] [x (cdr l)])
(if (pair? x)
(loop x (cdr x))
l))
(raise-type-error 'last-pair "pair" l))))