[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix `split-at-predicate' in `scm/lily-library.scm'.
From: |
Thomas |
Subject: |
[PATCH] Fix `split-at-predicate' in `scm/lily-library.scm'. |
Date: |
Tue, 10 Nov 2009 02:00:07 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Don't make the assumption that if `(PRED previous_element element)'
is false, `(PRED element previous_element)' must be true.
Suppose we want to split `(1 2 3 5 7)' into two lists such that
the first list contains the initial consecutive integers `(1 2 3)'
and the second contains the remaining elements `(5 7)'. We expect
`(split-at-predicate (lambda (x y) (= (- y x) 1)) '(1 2 3 5 7))'
to return `((1 2 3) . (5 7))', but in fact it returns `((1 2 3 5 7))'
because of this erroneous assumption.
---
scm/lily-library.scm | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index adb2bdf..1624288 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -343,7 +343,9 @@ found."
Example: (split-at-predicate < '(1 2 3 2 1)) ==> ((1 2 3) . (2 1))"
(if (null? lst)
(list lst)
- (let ((i (list-index pred (cdr lst) lst)))
+ (let ((i (list-index (lambda (x y) (not (pred x y)))
+ lst
+ (cdr lst))))
(if i
(cons (take lst (1+ i)) (drop lst (1+ i)))
(list lst)))))
--
1.6.0.4
- [PATCH] Fix `split-at-predicate' in `scm/lily-library.scm'.,
Thomas <=