+;; args are in reverse order, rest may specify additional ones
+;;
+;; If args is not a proper list, an error has been flagged earlier
+;; and no fallback value had been available. In this case,
+;; we don't call the function but rather return the general
+;; fallback.
+(define-ly-syntax (music-function parser loc fun args . rest)
+ (let* ((sig (ly:music-function-signature fun))
+ (pred (if (pair? (car sig)) (caar sig) (car sig)))
+ (good (proper-list? args))
+ (m (and good (apply (ly:music-function-extract fun)
+ parser loc (reverse! args rest)))))
+ (if (and good (pred m))
+ (begin
+ (if (ly:music? m)
+ (set! (ly:music-property m 'origin) loc))
+ m)