lilypond-user
[Top][All Lists]
Advanced

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

Re: Lilypond Substitution Function


From: Jean Abou Samra
Subject: Re: Lilypond Substitution Function
Date: Sat, 27 Feb 2021 16:43:42 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

Le 27/02/2021 à 02:16, Ken Ledeen a écrit :

I am struggling to understand the restrictions on substitution functions.

For example:

1) can a function include "\score { ...}"  or can it only be invoked INSIDE a \score?

2) is it possible to include \header { ...}  inside a substitution function?  It fails when I try, but I don't understand why.

I assume I am missing some basic concepts regarding their use.

Thanks!


Hello,

Music functions must return music objects; \score blocks are not music but general containers that enclose music as well as other objects such as \header and \layout blocks.

However, replacing define-music-function with define-scheme-function, you can define more versatile functions that are allowed to return any kind of object for interpretation. For example:

\version "2.23.1"

failingFunction =
#(define-music-function () ()
   #{
     \score {
       \header {
         piece = "Piece A"
       }
       { c' }
     }
   #})

% \failingFunction

succeedingFunction =
#(define-scheme-function () ()
   #{
     \score {
       \header {
         piece = "Piece B"
       }
       { c' }
     }
   #})

\succeedingFunction


Hope that helps,
Jean




reply via email to

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