David Sumbler <da...@aeolia.co.uk> writes: > On Tue, 2016-04-19 at 20:51 +0200, David Kastrup wrote: >> David Sumbler <da...@aeolia.co.uk> writes: >> >> > In starting to experiment with selective compilation using includes >> > and/or the $(if condition action) structure provided by David Kastrup, I >> > found that there is something very, very basic that I have never really >> > understood. >> > >> > So at the risk of embarrassing myself, I should be grateful if somebody >> > would explain the following: how does Lilypond recognize the end of a >> > variable definition? >> >> One expression. >> >> > For instance, an example from the documentation shows: >> > >> > violin = \new Staff { >> > \relative { >> > a'4 b c b >> > } >> > } >> >> "cello" can be no part of a single music expression, so it becomes a new >> statement. Actually, at this point there are very few possible >> continuations. But there is one: >> >> \addlyrics { oh right this one } >> >> > cello = \new Staff { >> > \relative { >> > \clef "bass" >> > e2 d >> > } >> > } >> > >> > What I don't understand is why the definition of 'violin' extends from >> > 'new' to the right brace on line 5. Why does the definition not extend, >> > for instance, to the brace on line 12? >> >> What would "cello" be? >> >> > Alternatively, why does 'violin' not equate simply to '\new' or to >> > '\new Staff' or '\new Staff {' ? >> >> All those are not a complete music expression. > > So Lilypond actually checks the syntax and structure of a variable at > the time it is defined.
It does not "check" it as much as read it in and evaluate it completely. If some expressions occur at top level, it does a default action. Scores a collected into the default book which is typeset at the end of run when non-empty. Books are typeset, bookparts are evaluated and stored in the default book and so on. But LilyPond is an interpreter, not a compiler. Expressions get parsed when they are encountered. > I assumed that only the validity of the name was checked, and that the > rest was simply stored as a string of characters. This is implied in > the docs, Where? It would be completely wrong. > although it may well be that elsewhere they do state that the string > must represent a complete music expression. There is no string here. Quite literally not. The lexer turns the input into tokens, and the parser collects the tokens into productions. Only in a minority of cases is an actual Scheme string produced from them: most of the time they are just characters in the input buffer. > Also from the documentation we have: > > width = 4.5\cm > name = "Wendy" > aFivePaper = \paper { paperheight = 21.0 \cm } > > None of these, as I (perhaps mis)understand it, is a music expression. I wrote "one expression", not "one music expression". > I can see that the definition of aFivePaper is perhaps terminated by > the '}' following the earlier '{'. And that the definition of name is > perhaps terminated by a double quote, since it commences with one. In > the case of width, it seems even less clear - perhaps it is that, in > the absence of an opening delineator such as ( { " etc., it regards > the first white space as a terminator. But I am guessing. > > Am I alone in finding the functioning of variable definition slightly > less than obvious? It's variable = expression and LilyPond knows a variety of different expressions. The expression is read in, and when it is finished, it is assigned to the variable with name "variable" (in this example). -- David Kastrup _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user