Jay Anderson wrote:
> Actually, I like this much better. A couple things:
> - It doesn't handle an empty list as input. Or is an error the correct
> behavior?
> - I'm not the biggest fan of multiple return values. You could do
> (cons (take lst (1+ i)) (drop lst (1+ i))) instead (unless there are
> efficiencies in the split-at approach).
> - I think (list lst) is clearer than `(,lst).
Thanks Jay,
take/drop seems clearer (and somehow more appropriate) than
call-with-values/split-at. Also thanks for testing '() -- it
slipped my mind during all the srfi excitement. The original
function handles empty lists so we need to keep it in.
Maybe at some point I'll make yet another patch!
- Mark
___________________________
(use-modules (srfi srfi-1))
(define-public (split-at-predicate predicate lst)
"Split a list into 2 lists at the first element that returns #f for
(PREDICATE previous_element element). Return the two parts as a pair.
Example: (split-at-predicate < '(1 2 3 2 1)) ==> ((1 2 3) . (2 1))"
(if (null? lst)
(list lst)
(let ((i (list-index predicate (cdr lst) lst)))
(if i
(cons (take lst (1+ i)) (drop lst (1+ i)))
(list lst)))))
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel