Mark Polesky wrote:
> 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).
I've updated ly:sort-alist to cope with non-numeric values.
Here they are again:
#(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)
(if (number? a)
(< (cdr a) (cdr b)))
(string<? (symbol->string (cdr a))
(symbol->string (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)))
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel