In creating a Julia script for interactive plotting of compound interest and mortgages, I’ve run into a problem. Here’s a skeleton of the essential parts:
using Gtk w, h = 200, 250 canvas = @GtkCanvas() win = GtkWindow(canvas, "Interest", w, h) amount = 1000 initialamount = 1000 function plotcurve() return 999 end @guarded draw(canvas) do widget gc = getgc(canvas) global amount amount = plotcurve() println("draw set amount=$amount") # amount changed correctly end # do function process() println("process called with amount = $amount") draw(canvas) showall(win) println("process: initial amount=$initialamount, finalamount=$amount") # amount unchanged end # process function process() println("initial amount=$initialamount, finalamount=$amount") # amount unchanged
Here’s the result of running it as an included script:
julia> include("desktop/globaltest.jl.txt") process called with amount = 1000 process: initial amount=1000, finalamount=1000 initial amount=1000, finalamount=1000 julia> draw set amount=999
How can the correct value of amount, as set in the draw function, be passed to the global variable, as needed in the full implementation? As this is for a course I’m creating, the simplest solution is desirable. Thanks for any help.