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: David Kastrup
Subject: Re: Function template (or whatever it's called)
Date: Wed, 20 Jun 2018 12:31:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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.

-- 
David Kastrup



reply via email to

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