[Top][All Lists]
[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)))))
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Patrick McCarty, 2009/06/04
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Neil Puttock, 2009/06/07
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/07
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/14
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Joe Neeman, 2009/06/15
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Jay Anderson, 2009/06/17
- Re: [PATCH] Make some local functions public, Mark Polesky, 2009/06/17
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/22
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Jay Anderson, 2009/06/23
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question),
Mark Polesky <=
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/23
- Re: [PATCH] Make some local functions public, Mark Polesky, 2009/06/23
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Han-Wen Nienhuys, 2009/06/23
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/23
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Han-Wen Nienhuys, 2009/06/24
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/24
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Carl D. Sorensen, 2009/06/24
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Jan Nieuwenhuizen, 2009/06/24
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Han-Wen Nienhuys, 2009/06/24
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Mark Polesky, 2009/06/24