|
|
@ -11,13 +11,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide/contract (slicef-at xs pred [force? #f])
|
|
|
|
(define+provide/contract (slicef-at xs pred [force? #f])
|
|
|
|
((list? procedure?) (boolean?) . ->* . list-of-lists?)
|
|
|
|
((list? procedure?) (boolean?) . ->* . list-of-lists?)
|
|
|
|
(define-values (last-list list-of-lists)
|
|
|
|
(define-values (last-list list-of-lists _)
|
|
|
|
(for/fold ([current-list empty][list-of-lists empty])([x (in-list xs)])
|
|
|
|
(for/fold ([current-list empty][list-of-lists empty][previous-x-was-pred #f])([x (in-list xs)])
|
|
|
|
(if (pred x)
|
|
|
|
(define pred-x (pred x))
|
|
|
|
|
|
|
|
(if (and (not previous-x-was-pred) pred-x)
|
|
|
|
(values (cons x null) (if (not (empty? current-list))
|
|
|
|
(values (cons x null) (if (not (empty? current-list))
|
|
|
|
(cons (reverse current-list) list-of-lists)
|
|
|
|
(cons (reverse current-list) list-of-lists)
|
|
|
|
list-of-lists))
|
|
|
|
list-of-lists) pred-x)
|
|
|
|
(values (cons x current-list) list-of-lists))))
|
|
|
|
(values (cons x current-list) list-of-lists pred-x))))
|
|
|
|
(let ([list-of-lists (reverse (if (empty? last-list)
|
|
|
|
(let ([list-of-lists (reverse (if (empty? last-list)
|
|
|
|
list-of-lists
|
|
|
|
list-of-lists
|
|
|
|
(cons (reverse last-list) list-of-lists)))])
|
|
|
|
(cons (reverse last-list) list-of-lists)))])
|
|
|
|