lilypond-devel
[Top][All Lists]
Advanced

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

Re: Building identifiers algorithmically


From: Trevor Daniels
Subject: Re: Building identifiers algorithmically
Date: Sat, 21 Mar 2015 23:56:08 -0000

Thanks Urs, that what I needed!

Trevor

----- Original Message ----- 
From: "Urs Liska" <address@hidden>
To: <address@hidden>
Sent: Saturday, March 21, 2015 10:44 PM
Subject: Re: Building identifiers algorithmically


> Hi Trevor,
> 
> hey, that's what I just learned :-)
> 
> What you need is (ly:parser-lookup parser 'SopranoMusic) inside a music 
> function.
> Then create the 'SopranoMusic symbol from two strings and you're good to go.
> 
> \version "2.19.18"
> 
> SopranoMusic = {
>   c' d'
> }
> 
> 
> getMusic =
> #(define-music-function (parser location label1 label2)
>    (string? string?)
>    (ly:parser-lookup parser
>      (string->symbol
>       (string-append label1 label2))))
> 
> \score {
>   \new Staff \getMusic "Soprano" "Music"
> }
> 
> HTH
> Urs
> 
> Am 21.03.2015 um 23:29 schrieb Trevor Daniels:
>> LilyPond Schemers,
>>
>> I'm gradually getting the hang of Scheme, but I'd like some help with one 
>> frustrating issue.  I'd like to build an identifier from two strings and use 
>> it to reference a LilyPond variable.
>>
>> In other words, I have several Lily variables defined like this
>>
>> SopranoMusic = \relative { ... }
>>
>> and I'd like to reference them from Scheme code using the strings "Soprano" 
>> and "Music".  The only way I've found is to build an alist of all of them 
>> using
>>
>> #(set! index (assoc-set! index "SopranoMusic" SopranoMusic))
>>
>> and then retrieve the music with
>>
>> #(define music (assoc-ref index (string-append "Soprano" "Music")))
>>
>> (In my real-use case of course some of the strings are variables.)
>>
>> Now while this works it seems rather clunky, so I'm wondering if there is a 
>> more elegant way of doing this.  Symbols look like they might help, but so 
>> far I've failed to make anything work.  I've also failed with macros, but 
>> that's likely because I don't understand them yet.
>>
>> TIA, Trevor
>> _______________________________________________
>> lilypond-devel mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/lilypond-devel
> 
> 
> _______________________________________________
> lilypond-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-devel

reply via email to

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