Re: Building identifiers algorithmically
On Sun, 2015-03-22 at 08:01 +0100, David Kastrup wrote: Trevor Daniels t.dani...@treda.co.uk writes: 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. When a function is evaluated, its arguments are read, evaluated, and the function is called with the unevaluated I guess you meant evaluated here??? Richard arguments, and the result of that call is used. When a macro is evaluated, its arguments are read, the macro is called with the unevaluated arguments, and the result of that call is evaluated before use. It's just a matter of where the evaluation happens. With a function, it is before the call, with a macro, it is after the call. That's all there is to it. ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Building identifiers algorithmically
Trevor Daniels t.dani...@treda.co.uk writes: 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. When a function is evaluated, its arguments are read, evaluated, and the function is called with the unevaluated arguments, and the result of that call is used. When a macro is evaluated, its arguments are read, the macro is called with the unevaluated arguments, and the result of that call is evaluated before use. It's just a matter of where the evaluation happens. With a function, it is before the call, with a macro, it is after the call. That's all there is to it. -- David Kastrup ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Building identifiers algorithmically
Richard Shann rich...@rshann.plus.com writes: On Sun, 2015-03-22 at 08:01 +0100, David Kastrup wrote: Trevor Daniels t.dani...@treda.co.uk writes: 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. When a function is evaluated, its arguments are read, evaluated, and the function is called with the unevaluated I guess you meant evaluated here??? Whoever was sitting at my keyboard better would have meant evaluated. arguments, and the result of that call is used. When a macro is evaluated, its arguments are read, the macro is called with the unevaluated arguments, and the result of that call is evaluated before use. It's just a matter of where the evaluation happens. With a function, it is before the call, with a macro, it is after the call. That's all there is to it. -- David Kastrup ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Building identifiers algorithmically
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 lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
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 lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel
Re: Building identifiers algorithmically
Thanks Urs, that what I needed! Trevor - Original Message - From: Urs Liska u...@openlilylib.org To: lilypond-devel@gnu.org 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 lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel ___ lilypond-devel mailing list lilypond-devel@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-devel