-(define-ly-syntax (music-function parser loc pred default fun args)
- (let ((m (apply fun parser loc args)))
- (if (pred m)
- m
- (begin
- (ly:parser-error parser
- (format #f (_ "~a function can't return ~a")
- (type-name pred) m)
- loc)
- default))))
+;; 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)
+ (begin
+ (if good
+ (ly:parser-error parser
+ (format #f (_ "~a function cannot return ~a")
+ (type-name pred)
+ (value->lily-string m parser))
+ loc))
+ (and (pair? (car sig)) (cdar sig))))))
+
+(define-ly-syntax (argument-error parser location n pred arg)
+ (ly:parser-error
+ parser
+ (format #f
+ (_ "wrong type for argument ~a. Expecting ~a, found ~s")
+ n (type-name pred) (music->make-music arg))
+ location))