lilypond-user
[Top][All Lists]
Advanced

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

Re: set variable


From: Aaron Hill
Subject: Re: set variable
Date: Fri, 19 Feb 2021 12:42:23 -0800
User-agent: Roundcube Webmail/1.4.9

On 2021-02-19 12:21 pm, Robert Kubosz wrote:
Hello

The default way to override an existing variable in scheme is:
#(define foo 2)
#(set! foo 3)
#(display foo) %--> output is 3

I want to override the foo with use of another variable storing the
foo's varname:

#(define foo 2)
#(define bar 'foo) %variable storing the foo's varname
#(set! `,bar 3)  %I want here to override the foo variable with use of bar
#(display foo) %---> the expected by me output is 3

How can I do this?

The set! macro expects the variable to be changed. On the other hand, module-set! expects a symbol naming the variable to be changed. If you know the variable is within the current-module, you can do this:

%%%%
\version "2.22.0"

#(define xyzzy 123)
#(format #t "\nxyzzy = ~s" xyzzy)
#(set! xyzzy -456)
#(format #t "\nxyzzy = ~s" xyzzy)
#(module-set! (current-module) 'xyzzy 78.9)
#(format #t "\nxyzzy = ~s" xyzzy)
%%%%
====
Parsing...
xyzzy = 123
xyzzy = -456
xyzzy = 78.9
Success: compilation successfully completed
====


-- Aaron Hill



reply via email to

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