[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: |
Tue, 23 Jun 2009 12:07:42 -0700 (PDT) |
I also took a look at the next procedure, split-list-by-separator.
My revised version is below. Unless I hear otherwise, I'll send a
patch soon.
- Mark
;; current version
(define-public (split-list-by-separator lst sep?)
"(display (split-list-by-separator '(a b c / d e f / g) (lambda (x) (equal?
x '/))))
=>
((a b c) (d e f) (g))
"
;; " Emacs is broken
(define (split-one sep? lst acc)
"Split off the first parts before separator and return both parts."
(if (null? lst)
(cons acc '())
(if (sep? (car lst))
(cons acc (cdr lst))
(split-one sep? (cdr lst) (cons (car lst) acc)))))
(if (null? lst)
'()
(let* ((c (split-one sep? lst '())))
(cons (reverse! (car c) '()) (split-list-by-separator (cdr c) sep?)))))
;; my version
; for [take, drop, list-index,] take-while and find-tail
(use-modules (srfi srfi-1))
(define-public (split-list-by-separator-NEW lst pred)
"Split LST at each element that satisfies PRED, and return the parts
(with the separators removed) as a list of lists.
(split-list-by-separator '(a 0 b c 1 d) number?) ==> ((a) (b c) (d))"
(let loop ((result '()) (lst lst))
(if (and lst (not (null? lst)))
(loop
(append result
(list (take-while (lambda (x) (not (pred x))) lst)))
(let ((tail (find-tail pred lst)))
(if tail (cdr tail) #f)))
result)))
;; compare return values
(display
(apply eq? #t
(map (lambda (x)
(equal? (split-list-by-separator x number?)
(split-list-by-separator-NEW x number?)))
'(() (0) (0 a) (0 a 1) (0 a 1 b) (0 1 a b) (0 a b 2 3)
(a) (a 0) (a 0 b) (a 0 b 1) (a b 0 1) (a 0 1 b c)))))
- 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, 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, 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
- Re: [PATCH] Make some local functions public (was: Re: lily-library.scm question), Carl D. Sorensen, 2009/06/24