lilypond-devel
[Top][All Lists]
Advanced

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

Building identifiers algorithmically


From: Trevor Daniels
Subject: Building identifiers algorithmically
Date: Sat, 21 Mar 2015 22:29:07 -0000

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

reply via email to

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