lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Function template (or whatever it's called)


From: Urs Liska
Subject: Function template (or whatever it's called)
Date: Wed, 20 Jun 2018 11:18:50 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]