lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: where to put useful lists in the docs?


From: Mark Polesky
Subject: Re: where to put useful lists in the docs?
Date: Mon, 25 May 2009 12:38:57 -0700 (PDT)

Mark Polesky wrote:
> Incidentally, I found I could simplify these with "filter":

Here's a proposal:

Here are two generic functions that could be incorporated into IR
4 "Scheme functions" (though if C++ is required, someone else
would have to help).

________________________

(define (ly:sort-alist alist prop)
  #! Return a sorted list of pairs (entry . prop-value) of "alist"
  entries that have "prop" as a key. !#
  (let ((value (lambda (a) (ly:assoc-get prop (cdr a)))))
    (sort-list (map (lambda (a) (cons (car a) (value a)))
                    (filter value alist))
               (lambda (a b) (< (cdr a) (cdr b))))))
              
(define (ly:filter-alist alist prop . value)
  #! Return a list of "alist" entries that have "prop" as a key (if
  "value" is unspecified), or that have "prop" set to "value" (if
  specified), or that do *not* have "prop" as a key (if "value" is
  'unset). !#
  (map car
       (filter
         (lambda (entry)
           (let ((this-value (ly:assoc-get prop (cdr entry) 'unset)))
             (if (null? value)
                 (not (eq? this-value 'unset))   ; value is set.
                 (eq? (car value) this-value)))) ; value is a match.
         alist)))

________________________

compile to test:

{
#(begin
; uncomment a line to test it.
;(display (ly:sort-alist default-script-alist 'script-priority))
;(display (ly:sort-alist all-grob-descriptions 'outside-staff-priority))

;(display (ly:filter-alist default-script-alist 'avoid-slur))
;(display (ly:filter-alist default-script-alist 'avoid-slur #f))
;(display (ly:filter-alist all-grob-descriptions 'avoid-slur))
;(display (ly:filter-alist all-grob-descriptions 'non-musical))
;(display (ly:filter-alist all-grob-descriptions 'non-musical 'unset))
)
}
________________________

This could save future developers valuable time during the
learning process.

Thoughts?

- Mark


      




reply via email to

[Prev in Thread] Current Thread [Next in Thread]