lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Make some local functions public (was: Re: lily-library.scm


From: Mark Polesky
Subject: Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question)
Date: Mon, 22 Jun 2009 22:06:53 -0700 (PDT)

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)))))



      




reply via email to

[Prev in Thread] Current Thread [Next in Thread]