Deniz, I think you could use a macro: [root@hd0 ~]# julia-0.5.0 _ _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: http://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.5.0-dev+1020 (2015-10-29 23:21 UTC) _/ |\__'_|_|_|\__'_| | Commit a36bb6d* (4 days old master) |__/ | x86_64-unknown-linux-gnu
julia> macro foo(k, v) quote $(esc(k)) = $v @show bar end end julia> @foo bar 42 bar = 42 42 julia> bar 42 julia> @foo baz bar + 1 bar = 42 42 julia> baz 43 El lunes, 2 de noviembre de 2015, 11:52:38 (UTC-6), Deniz Yuret escribió: > > If I have the following function: > > function foo(k,v) > @eval ($(symbol(k))=$v) > println(bar) > end > > > and I call it with: > > foo("bar", 5) > > then the global variable bar is set to 5 and the function prints 5. > > Is there any way to make @eval set a local variable inside foo instead? > (I tried prefixing the assignment with local which didn't work). > > thanks, > deniz > >