------------------------- Sunday, November 3, 2019, 2:24:10 PM, David Kastrup wrote:
> Peter Toye <lilyp...@ptoye.com> writes: >> Is there a case for introducing scoped variables into Lilypond? >> As I understand it (please correct me if I'm wrong), variables have to be >> declared at the top of the document, before any music expression. I'm trying >> to work on a document with many different scores, each if which is in its >> own file. According to what I gather is best practice I use variables to >> hold the basic music text: one variable for each staff. When engraving each >> individual score, I need to put its variable declarations at the head of its >> file. But when I want to gather them all together into a book or bookpart, >> this doesn't work, so each score has to be edited to remove the definitions. >> One way round this would be to allow Lilypond variables to be defined >> within bookparts and/or scores, and to give them a scope confined to >> that section. See the following MNWE. > So what happens with > bla = c' > sc = \score { \bla } > \book { > bla = f' > \sc > } > There are similar considerations for defining and using bookparts > outside of books: basically the question is > what scopes you even want to > be talking about, lexical or dynamical, and how the two would be > supposed to interact. Good question. It would need deciding and documenting. I agree there are two interpretations of what the writer might want. The simplest (IMO) would be to use lexical scope: sc is defined outside the \book and would use the global version of bla, so the output would be c'. If there were a music expression using bla inside the \book, it would use the local version and output f'. By allowing one to define sc and bla within the \score one could write each score independently of others, and name clashes would be avoided. That's something I failed to do in a multi-movement work before deciding that I might want it as a book:-(> As it is, six or seven staves over 8 movements is a lot of variable names to keep organised. I would prefer to keep the variable name the same for the content of each staff with the same instrument. It also means that when engraving each movement separately I don't have to keep track of exactly which variable definitions I need at the very top of the document (although I suppose the excess definitions don't hurt too much, except in storage space in the compiler). Regards, Peter