From 8a02b53ac24fa5ccf3eb816834af1d1d0092fdf9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 26 Nov 2014 12:59:31 -0800 Subject: [PATCH] fix break-at to allow empty breakpoint list as input --- list.rkt | 2 +- tests.rkt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/list.rkt b/list.rkt index 9c2e81f..a949f81 100644 --- a/list.rkt +++ b/list.rkt @@ -94,7 +94,7 @@ (define increasing-positive-list? (and/c list? increasing-positive?)) (define+provide/contract (break-at xs bps) - (list? (and/c coerce/list? increasing-positive-list?) . -> . (listof list?)) + (list? (and/c coerce/list? (or/c empty? increasing-positive-list?)) . -> . (listof list?)) (when (ormap (λ(bp) (>= bp (length xs))) bps) (error 'break-at (format "breakpoint in ~v is greater than or equal to input list length = ~a" bps (length xs)))) ;; easier to do back to front, because then the list index for each item won't change during the recursion diff --git a/tests.rkt b/tests.rkt index 1016b85..0696297 100644 --- a/tests.rkt +++ b/tests.rkt @@ -162,6 +162,8 @@ (check-equal? (sublist (range 5) 0 1) '(0)) (check-equal? (sublist (range 5) 0 5) '(0 1 2 3 4)) +(check-equal? (break-at '(5 6 7 8) '()) '((5 6 7 8))) (check-equal? (break-at '(5 6 7 8) '(1 2 3)) '((5) (6) (7) (8))) (check-equal? (break-at '(5 6 7 8) '(1 3)) '((5) (6 7) (8))) -(check-equal? (break-at '(5 6 7 8) '(1)) (break-at '(5 6 7 8) 1)) \ No newline at end of file +(check-equal? (break-at '(5 6 7 8) '(1)) (break-at '(5 6 7 8) 1)) +