[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: |
Sun, 7 Jun 2009 17:59:07 -0700 (PDT) |
Neil Puttock wrote:
> -(define (split-at-predicate predicate lst)
> +(define-public (split-at-predicate predicate lst)
>
> Can you amend the docstring for this, since the example given is
> a bit broken (the cons part shouldn't be there):
>
> (split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11)
> (cons '() '()))"
[PATCHES attached]
Neil, I ended up rewriting the procedure. Can you verify that I
didn't accidentally change some of its original functionality? I'm
pretty sure it's fine, but we like to be thorough, right? At the
moment, the only place I see this used in the source is in
chord-ignatzek-names.scm, line 250.
current version:
(define (split-at-predicate predicate lst)
"Split LST = (a_1 a_2 ... a_k b_1 ... b_k)
into L1 = (a_1 ... a_k ) and L2 =(b_1 .. b_k)
Such that (PREDICATE a_i a_{i+1}) and not (PREDICATE a_k b_1).
L1 is copied, L2 not.
(split-at-predicate (lambda (x y) (= (- y x) 2)) '(1 3 5 9 11) (cons '()
'()))"
;; " Emacs is broken
(define (inner-split predicate lst acc)
(cond
((null? lst) acc)
((null? (cdr lst))
(set-car! acc (cons (car lst) (car acc)))
acc)
((predicate (car lst) (cadr lst))
(set-car! acc (cons (car lst) (car acc)))
(inner-split predicate (cdr lst) acc))
(else
(set-car! acc (cons (car lst) (car acc)))
(set-cdr! acc (cdr lst))
acc)))
(let* ((c (cons '() '())))
(inner-split predicate lst c)
(set-car! c (reverse! (car c)))
c))
________________________________________________
my version:
(define-public (split-at-predicate predicate lst)
"Split LST (into 2 lists) at the first element that returns #f for
(PREDICATE previous_element element), and return the 2 new lists as a
pair. Example: (split-at-predicate < '(1 2 3 2 1)) ==> ((1 2 3) 2 1)"
(if (< (length lst) 2)
(cons lst '())
(let loop ((L0 (list (car lst))) (L1 (cdr lst)))
(cond ((null? L1) (cons L0 L1))
((predicate (car (last-pair L0))
(car L1))
(loop (append L0 (list (car L1)))
(cdr L1)))
(else (cons L0 L1))))))
________________________________________________
> - (define (inner-split predicate lst acc)
> + (define-public (inner-split predicate lst acc)
>
> This can't be public, since it's inside split-at-predicate.
Yes, of course... I blame it on poor indentation!
> -(define (number->octal-string x)
> +(define-public (number->octal-string x)
>
> Is this ever likely to be used?
Yes, I need it for my weekly octal game-night!
http://en.wikipedia.org/wiki/Octal_games
My abacus just isn't cutting it anymore.
- Mark
0001-lily-library.scm-Rewrite-split-at-predicate-procedur.patch
Description: Binary data
0002-lily-library.scm-Make-some-local-functions-public.patch
Description: Binary data
- 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 <=
- 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, 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