Urs Liska <li...@openlilylib.org> 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.

-- 
David Kastrup

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to