lilypond-user
[Top][All Lists]
Advanced

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

Re: chordmode using variable


From: Simon Albrecht
Subject: Re: chordmode using variable
Date: Thu, 28 Apr 2016 14:05:32 +0200

On 28.04.2016 11:52, Gianmaria Lari wrote:
Dear Harm,

some weeks ago replying to me, you used a variable name syntax that I
didn't know:

mynote.7 = .....
I see the compiler didn't complain and having the possibility to use
number in the variable name would be very practical (at least for me).
But is it a "standard programming style"?

It’s a quite new feature, undocumented and doesn’t work in all circumstances, but yes it is very useful. I don’t know whether you are familiar with Scheme; anyway here’s an explanation of the feature which I hope is correct:
mynote.7 = "foo"
uses an alist (<http://lilypond.org/doc/v2.19/Documentation/extending/scheme-compound-data-types#association-lists-_0028alists_0029>) to store the values, or more precisely, it assigns the value 1 to the key ‘7’ of the alist ‘mynote’. I.e. if mynote wasn’t defined previously, the Scheme equivalent of the example line would be:
#(define mynote `((7 . "foo")))
If it _was_ defined previously, it would be:
#(set! mynote (assoc-set! mynote 7 "foo"))
<http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Adding-or-Setting-Alist-Entries.html#Adding-or-Setting-Alist-Entries>

And \mynote.7 can be used to reference the value for the key 7 in the alist mynote. So for practical purposes, it’s /almost/ like you had a variable named ‘mynote.7’. But there are some caveats, e.g.:

\score { \mynote.7 } won’t work, you need to wrap it:
\score {
  { \mynote.7 }
}
or
\score {
  << \mynote.7 >>
}

Also, in lyricmode you need spaces around the dot separator: \lyricmode { \mynote . 7 }.

HTH, Simon



reply via email to

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