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