(- 2 (/ (ash 1 dotcount))))
(define-public (duration-length dur)
- "Return the overall length of a duration, as a number of whole notes.
-(Not to be confused with ly:duration-length, which returns a less-useful
- moment object.)"
+ "Return the overall length of a duration, as a number of whole
+notes. (Not to be confused with ly:duration-length, which returns a
+less-useful moment object.)"
(ly:moment-main (ly:duration-length dur)))
(define-public (duration-visual dur)
(symbol->string (car y))))
(define (map-alist-vals func list)
- "map FUNC over the vals of LIST, leaving the keys."
+ "map FUNC over the vals of LIST, leaving the keys."
(if (null? list)
'()
(cons (cons (caar list) (func (cdar list)))
(cons (cdar alist)
(flatten-alist (cdr alist))))))
-(define (assoc-remove key alist)
- "Remove key (and its corresponding value) from an alist.
- Different than assoc-remove! because it is non-destructive."
- (define (assoc-crawler key l r)
- (if (null? r)
- l
- (if (equal? (caar r) key)
- (append l (cdr r))
- (assoc-crawler key (append l `(,(car r))) (cdr r)))))
- (assoc-crawler key '() alist))
-
(define-public (map-selected-alist-keys function keys alist)
"Return @var{alist} with @var{function} applied to all of the values
in list @var{keys}.
@code{guile> (map-selected-alist-keys - '(a b) '((a . 1) (b . -2) (c . 3) (d . 4)))}
@code{((a . -1) (b . 2) (c . 3) (d . 4)}
@end example"
- (define (map-selected-alist-keys-helper function key alist)
+ (define (map-selected-alist-keys-helper key alist)
(map
(lambda (pair)
(if (equal? key (car pair))
(cons key (function (cdr pair)))
pair))
alist))
- (if (null? keys)
- alist
- (map-selected-alist-keys
- function
- (cdr keys)
- (map-selected-alist-keys-helper function (car keys) alist))))
+ (fold map-selected-alist-keys-helper alist keys))
;;;;;;;;;;;;;;;;
;; vector
(list elem)))
'() lst))
-(define-public (filtered-map proc lst)
- (filter
- (lambda (x) x)
- (map proc lst)))
+(define-public filtered-map filter-map)
(define-public (flatten-list x)
"Unnest list."
- (cond ((null? x) '())
- ((not (pair? x)) (list x))
- (else (append (flatten-list (car x))
- (flatten-list (cdr x))))))
+ (let loop ((x x) (tail '()))
+ (cond ((list? x) (fold-right loop tail x))
+ ((not (pair? x)) (cons x tail))
+ (else (loop (car x) (loop (cdr x) tail))))))
(define (list-minus a b)
"Return list of elements in A that are not in B."