lilypond-user
[Top][All Lists]
Advanced

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

Re: Function template (or whatever it's called)


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



Am 20.06.2018 um 11:38 schrieb David Kastrup:
Urs Liska <address@hidden> 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





reply via email to

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