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
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel