[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: |
Jay Anderson |
Subject: |
Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question) |
Date: |
Mon, 22 Jun 2009 21:03:42 -0700 |
On Mon, Jun 22, 2009 at 6:03 PM, Mark Polesky<address@hidden> wrote:
> I know, I know, I just won't let this die. I rewrote this silly
> function yet again (by now it's more of a programming exercise
> than anything else). But the things I've learned from everyone so
> far have found their way into my other LilyPond work, so I don't
> think it's a waste of time.
>
> I discovered 2 procedures from srfi-1 that can work in tandem for
> this: list-index and split-at. I'm left wondering if this is an
> improvement or not. I don't know the implications of use-modules;
> perhaps there's some overhead that I don't know about that isn't
> worth it. Or maybe list-index and split-at are less optimal than
> than Jay's loop-and-reverse solution.
>
> Just wanting to learn...
>
> Thanks,
> 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))"
> (let ((i (list-index predicate(cdr lst) lst)))
> (if i
> (call-with-values (lambda () (split-at lst (1+ i)))
> cons)
> `(,lst))))
> ___________________________
>
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).
-----Jay
- 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 <=
- 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), 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