However, be aware that this only works in global scope:

    function f()
       z=2.0
       change_variable(:z)
       println(z)
    end
    f()

will print 2. If this is a problem, you might wrap your variable in an 
array of size 1. 

    x=[2.0]
    change_variable(x)=x[1]=3



On Saturday, March 26, 2016 at 6:26:13 PM UTC+1, Lewis Lehe wrote:
>
> Hey Stefan,
> I figured it out. I had to do something along these lines:
>
> x = 2.0
> function change_variable(z)
>     eval(:($z = 3.0))
> end
> change_variable(:x)
>
>
>
>
>
> On Friday, March 25, 2016 at 12:00:50 PM UTC-7, Stefan Karpinski wrote:
>>
>> You may want to check out Interact.jl: 
>> https://github.com/JuliaLang/Interact.jl
>>
>> On Fri, Mar 25, 2016 at 1:59 PM, Lewis Lehe <[email protected]> wrote:
>>
>>> Err that is
>>>
>>>   slider[:on_changed](
>>>    #WHERE I WANT THE MACRO TO GO
>>>    variable = slider.val
>>>  )
>>>
>>>
>>>
>>> On Friday, March 25, 2016 at 10:57:34 AM UTC-7, Lewis Lehe wrote:
>>>>
>>>> Hi, 
>>>> I am learning about metaprogramming and macros. I have a very basic 
>>>> case but am unsure about what Julia is capable of. last time I asked a 
>>>> question here I got a very helpful answer shortly.
>>>>
>>>> I am making sliders for a matplotlib plot. I would that when a slider 
>>>> changes, it changes some the value of some variable. Here is an example.
>>>>
>>>> frequency = 2.0
>>>> function makeSlider(axSlider, variable):
>>>>   slider = widget.Slider(axSlider; valinit=variable)
>>>>   slider.on_changed(
>>>>     #WHERE I WANT THE MACRO TO GO
>>>>     variable = slider.val
>>>>   )
>>>>   slider
>>>> end
>>>> freqSlider = makeSlider(axFrequency,frequency)
>>>>
>>>>
>>>> Is this possible? I did not see any use cases like this in the 
>>>> documentation. 
>>>>
>>>> I would normally do it by keeping all my constants as properties of 
>>>> some World type (or in some world Dictionary) and passing the key to the 
>>>> function, but I wanted to learn how to use this part of Julia.
>>>>
>>>> Thanks!
>>>>
>>>
>>

Reply via email to