lilypond-user
[Top][All Lists]
Advanced

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

Re: chordmode using variable


From: Thomas Morley
Subject: Re: chordmode using variable
Date: Thu, 28 Apr 2016 21:30:08 +0200

2016-04-28 14:05 GMT+02:00 Simon Albrecht <address@hidden>:
> 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 <address@hidden>:
> 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



reply via email to

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