Am 20.06.2018 um 11:38 schrieb David Kastrup:
Urs Liska <[email protected]> writes:\version "2.19.80" myFunc = #(define-music-function (mus)(ly:music?) (let* ((elts (ly:music-property mus 'elements)) (cnt (length elts))) (ly:message "The music has ~a elements" cnt) mus)) { \myFunc { c' e' } } Create a music function with one ly:music? argument and extract some information from the music expression (of course this is just an example, in the real case it's a custom object attached to the music). What I would like to have is what define-music-function does here but with a pre-set argument list and essentially the let* bindings transparently done so that something like this is possible: userFunc = #(define-my-custom-function (ly:message "The music has ~a elements" cnt)) where one ly:music? argument is implicitly expected and the bindings like 'cnt' have already been prepared.#(define-macro (define-my-custom-function . body) `(define-music-function (mus) (ly:music?) (let* ((elts (ly:music-property mus 'elements)) (cnt (length elts))) ,@body mus))) That's what one would call a pretty unhygienic macro since it messes with a number of symbols/identifiers not specified by the user.
Hm, valid point. But I think it is worth it given the use case (I will experiment and keep your point in mind, though).
Best Urs
_______________________________________________ lilypond-user mailing list [email protected] https://lists.gnu.org/mailman/listinfo/lilypond-user
