2016-04-28 14:05 GMT+02:00 Simon Albrecht <simon.albre...@mail.de>: > 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,
Yes and no. For setting alists it worked for some time already. \version "2.16.2" myAlist = #'() myAlist #'foo = "foo" #(write-me "myAlist " myAlist) Note the need to use #' in myAlist #'foo = "foo" Dotted-separated lists didn't work back in 2.16 And only symbols (and strings) worked. In 2.18.2 dotted-separated lists were implemented, i.e.: \version "2.18.2" myAlist = #'() myAlist.foo = "foo" #(write-me "myAlist " myAlist) Now, 2.19.40 numbers work as well, i.e.: \version "2.19.40" myAlist = #'() myAlist.1 = "foo" #(write-me "myAlist " myAlist) So far setting alists. But with this development this syntax is now usable to define identifiers. Simon's explanation looks correct about how it works and it's limits. > 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 2016-04-28 14:25 GMT+02:00 Gianmaria Lari <gianmarial...@gmail.com>: > Thank you Simon for the explanation. I think I will try to avoid it as > much as possible but not more than that:) No need to avoid it, use it where sensible. Soemething at the lines of: \version "2.19.40" chrd.7 = \chordmode { c:7 } chrd.9 = \chordmode { c:9 } %% etc %% To define a single pitch don't use {} mynote = cis Cis.7 = \transpose c \mynote \chrd.7 Cis.9 = \transpose c \mynote \chrd.9 %% etc \chordmode { \Cis.7 \Cis.9 } Although I still have no clue why you want it this way... Cheers, Harm _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user