lilypond-user
[Top][All Lists]
Advanced

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

Re: Use String to reference Variable


From: Jan-Peter Voigt
Subject: Re: Use String to reference Variable
Date: Tue, 4 Dec 2018 09:37:27 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

Hello Pedro,

Am 04.12.18 um 04:28 schrieb Pedro Pessoa:
> Hello!
> I want a function that takes a string as arg an from that produces a valid
> variable reference, as follows:
> 
> %%% pseudo 
> Nabc={a1 d e f}
> Nxyz={b1 e a d}
> 
> fun=
> #(define-music-function (x)(string?)
>    #{
>      <<
>        #(concat x "abc")
>        \\
>        #(concat x "xyz")
>      >>
>    #})
> 
> \fun "N" %produces parallel music with Nabc and Nxyz
> %%%
> 
> ---
> 
> I've ran this test:
> 
> %%%
> \Nabc={some music}
> (display (string->symbol (string-append "N" "abc")))
> %%%
> 
> It outputs "Nabc", not the music content of Nabc, as I expected.
> Why is that? How do I make it point to the actual music?
The string is converted to a symbol and a symbol is a primitive datatype
in guile-scheme. To receive the value of the variable you have to ask
the parser. To place the result in the music you should use an instant
scheme expression (introduced by '$' not '#').

HTH:

fun=
#(define-music-function (x)(string?)
   #{
     <<
       $(ly:parser-lookup (string->symbol (string-append x "abc")))
       \\
       $(ly:parser-lookup (string->symbol (string-append x "xyz")))
     >>
   #})


Jan-Peter



reply via email to

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