2014-06-05 15:12 GMT+02:00 Paul Morris <p...@paulwmorris.com>: > Thomas Morley-2 wrote [...] >> And really hackish is: >> >> test = >> #(define-music-function (parser location test-arg mus) >> ( >> ;very bad, kludgy and hacky, though valid: >> ((lambda (x) (or (boolean? x) (number? x) (procedure? x))) "") >> ;scheme? >> ly:music? >> ) >> >> (cond ((boolean? test-arg) >> (format #t "\n~a is a boolean." test-arg)) >> ((number? test-arg) >> (format #t "\n~a is a number." test-arg)) >> ((procedure? test-arg) >> (format #t "\n~a is a procedure." test-arg)) >> (else #f)) >> mus) >> >> m = { c''1 } >> >> \test ##f \m >> \test #3 \m >> \test #(lambda (a) a) \m > > Good point about "scheme?", although it is so general that it doesn't tell > you which combination of types are expected, while this does: > > ((lambda (x) (or (boolean? x) (number? x) (procedure? x))) "") > > I'm not sure I understand why this is so bad. It seems better than > "scheme?" here since it is more specific. I had tried to do this before but > I didn't know I needed to include the "" at the end. (I assume this "" is > the description and could be changed to "boolean, number, or procedure" so > error messages would be accurate.)
No. It abuses the syntax for an _optional_ argument, with the default "" Look at: testII = #(define-music-function (parser location test-arg mus) ( ;very bad, kludgy and hacky, though valid: ((lambda (x) (or (boolean? x) (number? x) (procedure? x))) "xy") ;scheme? ly:music? ) (format #t "\nThe default for \"test-arg\" is ~a." test-arg) mus) m = { c''1 } \testII \m Cheers, Harm _______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel