I'm providing users with the option to configure some behaviour by providing custom styling functions. These functions must have a certain interface and will typically retrieve the same information from their arguments. I would like to simplify this task by providing a "function template". I think this may be achieved by macros or some other syntactic extension mechansim, but I have no idea about how to go forward with that.

This is what currently a user would have to do:

\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.

Is this possible? I would assume so, and I'd also would assume it's quite easy - once you know what to look for.

Thanks
Urs


_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to