]> git.donarmstrong.com Git - lilypond.git/commitdiff
remove tail, filter-list, filter-out-list,
authorhanwen <hanwen>
Wed, 2 Jul 2003 01:03:59 +0000 (01:03 +0000)
committerhanwen <hanwen>
Wed, 2 Jul 2003 01:03:59 +0000 (01:03 +0000)
first-n, butfirst-n in favor of srfi-1 functions

14 files changed:
ChangeLog
lily/molecule-scheme.cc
scm/bass-figure.scm
scm/chord-entry.scm
scm/chord-generic-names.scm
scm/chord-ignatzek-names.scm
scm/chord-name.scm
scm/document-backend.scm
scm/document-music.scm
scm/font.scm
scm/lily.scm
scm/music-functions.scm
scm/new-markup.scm
scm/to-xml.scm

index f028787940a148ec5e74d6ce4aa049085cef68b5..af356fd9c63378fa68e4195e615e6e227f0934f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2003-07-02  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * scm/lily.scm: remove tail, filter-list, filter-out-list,
+       first-n, butfirst-n in favor of srfi-1 functions
+
        * mf/parmesan-custodes.mf (dir_down): remove _ from glyph names.
 
        * NEWS: use complete sentences.
index 6a611efcd4014c04fba9553e652dc917041cbccb..8ba102f34d2f040090861360dd3644a6c5f3b2be 100644 (file)
@@ -119,7 +119,8 @@ LY_DEFINE(ly_molecule_combined_at_edge,
 }
 
 /*
-  FIXME: support variable number of arguments "
+  FIXME: support variable number of arguments. 
+  
  */
 LY_DEFINE(ly_molecule_add , 
          "ly:molecule-add", 2, 0, 0, (SCM first, SCM second),
index cfe44b6b94d9796dfbefb716e9c65c3f5989faa2..e65b116e49b446486b6c836b2ffa565664cc22c3 100644 (file)
@@ -9,7 +9,7 @@
   (if (null? l)
       '()
       (let*
-         ((x (split-at pred? l)))
+         ((x (split-at-predicate pred? l)))
        (set-cdr! x (recursive-split-at pred? (cdr x)))
        x
        )))
index f71ff585036279b7eac8d1b195320f338eda1694..6b047797ffb851abe08bb6ad4e61f4632b0aaa90 100644 (file)
@@ -113,8 +113,8 @@ the bass specified.
                           (ly:pitch-alteration inversion))
                        )))
                 
-          (rest-of-chord (filter-out-list inv? complete-chord))
-          (inversion-candidates (filter-list inv? complete-chord))
+          (rest-of-chord (remove inv? complete-chord))
+          (inversion-candidates (filter inv? complete-chord))
           (down-inversion (pitch-octavated-strictly-below inversion root))
           )
 
index fb9c1d3b10b6bfe9ae9d187038905d4434d508f7..8caaa4c8d0ea304f56c923a574e93f565be19c24 100644 (file)
@@ -113,7 +113,7 @@ input/test/dpncnt.ly).
     (make-line-markup (list (make-simple-markup "no") (step->markup pitch))))
                         
   (define (get-full-list pitch)
-    (if (<= (step-nr pitch) (step-nr (tail pitches)))
+    (if (<= (step-nr pitch) (step-nr (last pitches)))
        (cons pitch (get-full-list (next-third pitch)))
        '()))
 
@@ -139,7 +139,7 @@ input/test/dpncnt.ly).
     (if (pair? exceptions)
        (let* ((e (car exceptions))
               (e-pitches (car e)))
-         (if (equal? e-pitches (first-n (length e-pitches) pitches))
+         (if (equal? e-pitches (take pitches (length e-pitches) ))
              e
              (partial-match (cdr exceptions))))
        #f))
@@ -165,15 +165,15 @@ input/test/dpncnt.ly).
         ;; kludge alert: replace partial matched lower part of all with
         ;; 'normal' pitches from full
         ;; (all pitches)
-        (all (append (first-n (length partial-pitches) full)
-                     (butfirst-n (length partial-pitches) pitches)))
+        (all (append (take full (length partial-pitches) )
+                     (drop pitches (length partial-pitches) )))
              
-        (highest (tail all))
+        (highest (last all))
         (missing (list-minus full (map pitch-unalter all)))
         (consecutive (get-consecutive 1 all))
         (rest (list-minus all consecutive))
-        (altered (filter-list step-even-or-altered? all))
-        (cons-alt (filter-list step-even-or-altered? consecutive))
+        (altered (filter step-even-or-altered? all))
+        (cons-alt (filter step-even-or-altered? consecutive))
         (base (list-minus consecutive altered)))
         
 
@@ -260,7 +260,7 @@ input/test/dpncnt.ly).
               
               ;; kludge alert: omit <= 5
               ;;(markup-join (map step->markup
-              ;;                        (cons (tail base) cons-alt)) sep)
+              ;;                        (cons (last base) cons-alt)) sep)
               
               ;; This fixes:
               ;;  c     C5       -> C
@@ -269,7 +269,7 @@ input/test/dpncnt.ly).
               ;;  c:6.9 C5 6add9 -> C6 add 9 (add?)
               ;;  ch = \chords { c c:2 c:3- c:6.9^7 }
               (markup-join (map step->markup
-                                (let ((tb (tail base)))
+                                (let ((tb (last base)))
                                   (if (> (step-nr tb) 5)
                                       (cons tb cons-alt)
                                       cons-alt))) sep)
index 120bd68127da6e99ed6690cc429683fa3ce8ccf5..3e19987611e7e438bb45489bf1cfb4e0ff9448d0 100644 (file)
@@ -152,7 +152,7 @@ work than classifying the pitches."
        '()
        (let*
           (
-           (l (filter-list altered? alters))
+           (l (filter altered? alters))
            (lp (last-pair alters))
            )
 
@@ -273,7 +273,7 @@ work than classifying the pitches."
           (
            (3-diff? (lambda (x y)
                       (= (- (pitch-step y) (pitch-step x)) 2)))
-           (split (split-at 3-diff? (remove-uptil-step 5 pitches)))
+           (split (split-at-predicate 3-diff? (remove-uptil-step 5 pitches)))
            )
         (set! alterations (append alterations (car split)))
         (set! add-steps (append add-steps (cdr split)))
@@ -296,10 +296,10 @@ work than classifying the pitches."
              (= 7 (pitch-step main-name))
              (is-natural-alteration? main-name)
              (pair? (remove-uptil-step 7 alterations))
-             (reduce (lambda (x y) (and x y))
+             (reduce (lambda (x y) (and x y)) #t
                      (map is-natural-alteration? alterations)))
             (begin
-              (set! main-name (tail alterations))
+              (set! main-name (last alterations))
               (set! alterations '())
               ))
         
index 3e5c9f0ea7c908da8f5d5b8a09e0288e7574a474..7ed0f184d45a2def72881b8407353c1bc0ea6d4c 100644 (file)
@@ -89,7 +89,7 @@ FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
     (let* ((elts (ly:get-mus-property m 'elements))
           (omit-root (and (pair? rest) (car rest)))
           (pitches (map (lambda (x) (ly:get-mus-property x 'pitch))
-                        (filter-list
+                        (filter
                          (lambda (y) (memq 'note-event
                                            (ly:get-mus-property y 'types)))
                          elts)))
@@ -104,7 +104,7 @@ FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
           (diff (ly:pitch-diff root (ly:make-pitch 0 0 0)))
           (normalized (map (lambda (x) (ly:pitch-diff x diff)) sorted))
           (texts (map (lambda (x) (ly:get-mus-property x 'text))
-                      (filter-list
+                      (filter
                        (lambda (y) (memq 'text-script-event
                                          (ly:get-mus-property y 'types)))
                        elts)))
@@ -117,9 +117,9 @@ FOOBAR-MARKUP) if OMIT-ROOT is given and non-false.
      (memq 'event-chord (ly:get-mus-property m 'types))
      (not (equal? (ly:make-moment 0 1) (ly:get-music-length m)))))
 
-  (let* ((elts (filter-list is-req-chord? (ly:get-mus-property seq 'elements)))
+  (let* ((elts (filter is-req-chord? (ly:get-mus-property seq 'elements)))
         (alist (map chord-to-exception-entry elts)))
-    (filter-list (lambda (x) (cdr x)) alist)))
+    (filter (lambda (x) (cdr x)) alist)))
 
 
 (define-public (new-chord-name-brew-molecule grob)
index 94047ab8f8443600268230ae5ba9cb3c4be97779..7603f5d94248961fa9f3dc466cb8853791a8c8e0 100644 (file)
@@ -109,7 +109,7 @@ node."
 "\n\n"
                        (interface-doc-string iface description)))
                      (reverse ifaces)))
-       (engravers (filter-list
+       (engravers (filter
                   (lambda (x) (engraver-makes-grob? name x)) all-engravers-list))
        (namestr (symbol->string name))
        (engraver-names (map ly:translator-name engravers))
index bd6a8ea7efe3e10ce39d71fcbb55a212f8cf4bee..9b14484a30dd699e62ef523bd93f044fb0c772eb 100644 (file)
@@ -58,7 +58,7 @@
      (human-listify
       (map ref-ify
       (map ly:translator-name
-          (filter-list
+          (filter
            (lambda (x) (engraver-accepts-music-type? (car entry) x)) all-engravers-list))))
      "\n\n"
      )))
@@ -89,7 +89,7 @@
      (human-listify
       (map ref-ify
       (map ly:translator-name
-          (filter-list
+          (filter
            (lambda (x) (engraver-accepts-music-types? types x)) all-engravers-list))))
      "\n\nProperties: \n"
      (description-list->texi
index 34dd63b130a49bde510929ad9d1f302c8381a479..fa6835c34092e09307a075f1dfb7c85b07d0f81c 100644 (file)
@@ -33,7 +33,7 @@
 
 (define (filter-field field-name value font-descr-alist)
   "return those descriptions from FONT-DESCR-LIST whose FIELD-NAME matches VALUE"
-      (filter-list
+      (filter
        (lambda (x) (let* (field-value (font-field field-name (car x))) 
                     (or (eq? field-value '*) (eq? value field-value))))
        font-descr-alist)
@@ -346,7 +346,7 @@ and warn if the selected font is not unique.
 
 (if #f (begin
         (define (test-module)
-          (display (filter-list pair? '(1 2 (1 2) (1 .2)))
+          (display (filter pair? '(1 2 (1 2) (1 .2)))
                    (display (filter-field 'font-name 'cmbx paper20-style-sheet-alist))
                    
                    (display (qualifiers-to-fontname '((font-name . cmbx)) paper20-style-sheet-alist))
index 37b6812b285147fe4cadb8d16b9357547271dd0c..9866b1efc602bed32b1abb6a5a4c72824740ec84 100644 (file)
@@ -8,8 +8,8 @@
 ;;; Library functions
 
 
-(use-modules (ice-9 regex))
-
+(use-modules (ice-9 regex)
+            (srfi srfi-1))
 
 ;;; General settings
 ;; debugging evaluator is slower.
 
 ;;;;;;;;;;;;;;;;
 ; list
-(define (tail lst)
-  "Return tail element of LST."
-  (car (last-pair lst)))
-
 
 (define (flatten-list lst)
   "Unnest LST" 
 
 (define (list-minus a b)
   "Return list of elements in A that are not in B."
-  (if (pair? a)
-      (if (pair? b)
-         (if (member (car a) b)
-             (list-minus (cdr a) b)
-             (cons (car a) (list-minus (cdr a) b)))
-         a)
-      '()))
-
-;; TODO: use the srfi-1 partition function.
-
-;; why -list suffix (see reduce-list)
-(define-public (filter-list pred? list)
-  "return that part of LIST for which PRED is true.
-
- TODO: rewrite using accumulator. Now it takes O(n) stack. "
-  
-  (if (null? list) '()
-      (let* ((rest (filter-list pred? (cdr list))))
-       (if (pred? (car list))
-           (cons (car list)  rest)
-           rest))))
-
-(define-public (filter-out-list pred? list)
-  "return that part of LIST for which PRED is false."
-  (if (null? list) '()
-      (let* ((rest (filter-out-list pred? (cdr list))))
-       (if (not (pred? (car list)))
-           (cons (car list)  rest)
-           rest))))
-
+  (lset-difference eq? a b))
 
-(define (first-n n lst)
-  "Return first N elements of LST"
-  (if (and (pair? lst)
-          (> n 0))
-      (cons (car lst) (first-n (- n 1) (cdr lst)))
-      '()))
 
+;; TODO: use the srfi-1 partition function.
 (define-public (uniq-list list)
   (if (null? list) '()
       (if (null? (cdr list))
              (uniq-list (cdr list))
              (cons (car list) (uniq-list (cdr list)))))))
 
-(define (butfirst-n n lst)
-  "Return all but first N entries of LST"
-  (if (pair? lst)
-      (if (> n 0)
-         (butfirst-n (- n 1) (cdr lst))
-         lst)
-      '()))
-  
-(define (split-at predicate l)
+(define (split-at-predicate predicate l)
  "Split L = (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 (lambda (x y) (= (- y x) 2))  '(1 3 5 9 11) (cons '() '()))"
+(split-at-predicate (lambda (x y) (= (- y x) 2))  '(1 3 5 9 11) (cons '() '()))"
 ;; "
 
 ;; KUT EMACS MODE.
@@ -208,19 +162,16 @@ L1 is copied, L2 not.
 
 
 (define-public (split-list l sep?)
-  "
-
+"
 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
 =>
 ((a b c) (d e f) (g))
 
 "
+;; " KUT EMACS.
 
 (define (split-one sep?  l acc)
-  "Split off the first parts before separator and return both parts.
-
-"
-  ;; " KUT EMACS
+  "Split off the first parts before separator and return both parts."
   (if (null? l)
       (cons acc '())
       (if (sep? (car l))
@@ -233,19 +184,8 @@ L1 is copied, L2 not.
     '()
     (let* ((c (split-one sep? l '())))
       (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
-      )
-    )
-)
-
-
-(define-public (range x y)
-  "Produce a list of integers starting at Y with X elements."
-  (if (<= x 0)
-      '()
-      (cons y (range (- x 1)  (+ y 1)))
+      )))
 
-      )
-  )
 
 (define-public (interval-length x)
   "Length of the number-pair X, when an interval"
@@ -276,30 +216,13 @@ L1 is copied, L2 not.
   "map F to contents of X"
   (cons (f (car x)) (f (cdr x))))
 
-;; used where?
-(define-public (reduce operator list)
+;; TODO: remove.
+(define-public (reduce-no-unit operator list)
   "reduce OP [A, B, C, D, ... ] =
    A op (B op (C ... ))
 "
       (if (null? (cdr list)) (car list)
-         (operator (car list) (reduce operator (cdr list)))))
-
-(define (take-from-list-until todo gathered crit?)
-  "return (G, T), where (reverse G) + T = GATHERED + TODO, and the last of G
-is the  first to satisfy CRIT
-
- (take-from-list-until '(1 2 3  4 5) '() (lambda (x) (eq? x 3)))
-=>
- ((3 2 1) 4 5)
-
-"
-  (if (null? todo)
-      (cons gathered todo)
-      (if (crit? (car todo))
-         (cons (cons (car todo) gathered) (cdr todo))
-         (take-from-list-until (cdr todo) (cons (car todo) gathered) crit?)
-      )
-  ))
+         (operator (car list) (reduce-no-unit operator (cdr list)))))
 
 (define-public (list-insert-separator list between)
   "Create new list, inserting BETWEEN between elements of LIST"
index 3945e10a557144e60471bc43f9d203413b32cb88..8bffc5e52f35dcb6eb870cad5ee23556a2f56ae8 100644 (file)
@@ -272,8 +272,8 @@ a property set for MultiMeasureRestNumber."
          (
           (text? (lambda (x) (memq 'script-event (ly:get-mus-property x 'types))))
           (es (ly:get-mus-property  music 'elements))
-          (texts (map script-to-mmrest-text  (filter-list text? es)))
-          (others (filter-out-list text? es))
+          (texts (map script-to-mmrest-text  (filter text? es)))
+          (others (remove text? es))
           )
        (if (pair? texts)
            (ly:set-mus-property!
@@ -452,7 +452,7 @@ Rest can contain a list of beat groupings
         (ly:set-mus-property! m 'element  (voicify-music e)))
      (if
       (and (equal? (ly:music-name m) "Simultaneous_music")
-          (reduce (lambda (x y ) (or x y))     (map music-separator? es)))
+          (reduce (lambda (x y ) (or x y)) #f (map music-separator? es)))
       (voicify-chord m)
       )
 
@@ -498,7 +498,7 @@ Rest can contain a list of beat groupings
 ;; warn for bare chords at start.
 
 (define (has-request-chord elts)
-  (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly:music-name x)
+  (reduce (lambda (x y) (or x y)) #f (map (lambda (x) (equal? (ly:music-name x)
                                                           "Request_chord")) elts)
   ))
 
index 1ddde4bd9a46179b61d7c2310fd9019093c52cb8..f04cf768d8e3b980ee2089bf75e1b7d922e248ff 100644 (file)
@@ -223,13 +223,13 @@ for the reader.
        (dot (ly:find-glyph-by-name font "dots-dot"))
        (dotwid  (interval-length (ly:molecule-get-extent dot X)))
        (dots (if (> dot-count 0)
-                (reduce
+                (reduce-no-unit        ; TODO: use reduce.
                  (lambda (x y)
                    (ly:molecule-add x y))
                  (map (lambda (x)
                         (ly:molecule-translate-axis
                          dot  (* (+ 1 (* 2 x)) dotwid) X) )
-                      (range dot-count 1)))
+                      (iota dot-count 1)))
                 #f
                 ))
        
index 52d3513ffeb7c700059812fba29ea234b79dff6c..88f84280e3c0cbb763fdd382e1e2f433cb79d923 100644 (file)
@@ -152,7 +152,7 @@ is then separated.
   (string-append
    "<" (symbol->string tag)
    (apply string-append
-         (map dump-attr (filter-list candidate? attrs)))
+         (map dump-attr (filter candidate? attrs)))
    ">\n")
    
   )