lilypond-user
[Top][All Lists]
Advanced

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

Re: set variable


From: Robert Kubosz
Subject: Re: set variable
Date: Fri, 19 Feb 2021 21:47:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

Aaron, thank you!

This is something I was looking for.

On 19.02.2021 21:42, Aaron Hill wrote:
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]