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

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to