From: David Kastrup Date: Mon, 18 Feb 2013 10:53:56 +0000 (+0100) Subject: Issue 3196: Cleanup scm/lily-library.scm somewhat more X-Git-Tag: release/2.17.13-1~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cd03b4acd13af6f61fdf153e8b4ff506b94ecad7;p=lilypond.git Issue 3196: Cleanup scm/lily-library.scm somewhat more --- diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 5b39cc46ff..00f91e3116 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -144,27 +144,23 @@ duration (base note length and dot count), as a number of whole notes." (define-public (collect-music-aux score-handler parser music) (define (music-property symbol) - (let ((value (ly:music-property music symbol))) - (if (not (null? value)) - value - #f))) + (ly:music-property music symbol #f)) (cond ((music-property 'page-marker) ;; a page marker: set page break/turn permissions or label - (begin - (let ((label (music-property 'page-label))) - (if (symbol? label) - (score-handler (ly:make-page-label-marker label)))) - (for-each (lambda (symbol) - (let ((permission (music-property symbol))) - (if (symbol? permission) - (score-handler - (ly:make-page-permission-marker symbol - (if (eqv? 'forbid permission) - '() - permission)))))) - (list 'line-break-permission 'page-break-permission - 'page-turn-permission)))) - ((not (music-property 'void)) + (let ((label (music-property 'page-label))) + (if (symbol? label) + (score-handler (ly:make-page-label-marker label)))) + (for-each (lambda (symbol) + (let ((permission (music-property symbol))) + (if (symbol? permission) + (score-handler + (ly:make-page-permission-marker symbol + (if (eq? 'forbid permission) + '() + permission)))))) + '(line-break-permission page-break-permission + page-turn-permission))) + ((not (music-property 'void)) ;; a regular music expression: make a score with this music ;; void music is discarded (score-handler (scorify-music music parser))))) @@ -185,21 +181,16 @@ duration (base note length and dot count), as a number of whole notes." (define-public (scorify-music music parser) "Preprocess @var{music}." - - (for-each (lambda (func) - (set! music (func music parser))) - toplevel-music-functions) - - (ly:make-score music)) - + (ly:make-score + (fold (lambda (f m) (f m parser)) + music + toplevel-music-functions))) (define (get-current-filename parser book) "return any suffix value for output filename allowing for settings by calls to bookOutputName function" - (let ((book-filename (paper-variable parser book 'output-filename))) - (if (not book-filename) - (ly:parser-output-name parser) - book-filename))) + (or (paper-variable parser book 'output-filename) + (ly:parser-output-name parser))) (define (get-current-suffix parser book) "return any suffix value for output filename allowing for settings by calls to @@ -591,28 +582,27 @@ for comparisons." "Split LST into two lists at the first element that returns #f for (PRED 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 (lambda (x y) (not (pred x y))) - lst - (cdr lst)))) - (if i - (cons (take lst (1+ i)) (drop lst (1+ i))) - (list lst))))) + (let ((i (and (pair? lst) + (list-index (lambda (x y) (not (pred x y))) + lst + (cdr lst))))) + (if i + (call-with-values + (lambda () (split-at lst (1+ i))) + cons) + (list lst)))) (define-public (split-list-by-separator lst pred) "Split @var{lst} at each element that satisfies @var{pred}, and return the parts (with the separators removed) as a list of lists. For example, executing @samp{(split-list-by-separator '(a 0 b c 1 d) number?)} returns @samp{((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))) + (call-with-values (lambda () (break pred lst)) + (lambda (head tail) + (cons head + (if (null? tail) + tail + (split-list-by-separator (cdr tail) pred)))))) (define-public (offset-add a b) (cons (+ (car a) (car b))