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: Thu, 21 Jun 2018 22:37:18 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Hi Jan-Peter and David,


Am 20.06.2018 um 12:31 schrieb David Kastrup:
Urs Liska <address@hidden> writes:

Am 20.06.2018 um 11:38 schrieb David Kastrup:

#(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).
By the way, you'll probably arrive at something like

#(define-macro (define-my-custom-function maybe-doc . body)
     `(define-music-function (mus) (ly:music?)
        ,(if (string? maybe-doc) maybe-doc
                                 "define-my-custom-function was here")
        (let*
          ((elts ...
             ,@(if (string? maybe-doc) body (cons maybe-doc body)))

in order to let the user potentially specify a doc string.

Thanks for your help and explanation. I think I managed to get to a nice point that will give users of the package a concise way to define styling functions, without having to over and over repeat tedious and potentially confusing code. (I'll post a link when it's ready and pushed). Of course it's "unclean" because it will provide local bindings that are totally not obvious from the user code, but I think (now more than initially) that with sufficient documentation this is more than worth the effort.

Urs





reply via email to

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