http://stackoverflow.com/questions/35051773/create-local-variables-programmatically-from-a-dictionary-in-julia

On Wed, Jan 27, 2016 at 11:45 PM, Ethan Anderes <[email protected]>
wrote:

> This isn't exactly what you want... but you can always can splat
> `Dict{Symbol, T}` into named function argument like this
>
> ```
> julia> function f(;a = 0, b = 0, c = 0)
>         println("a = $a, b = $b, c = $c")
>        end
> f (generic function with 1 method)
>
> julia> dic = Dict(:a => 1, :b => 2, :c => 3)
> Dict{Symbol,Int64} with 3 entries:
>   :c => 3
>   :a => 1
>   :b => 2
>
> julia> f(;dic...)
> a = 1, b = 2, c = 3
> ```
>
> I guess you could then use meta programing to define `f` with named
> arguments for a specific `dic`, then call `f(;dic...)`. However, I'm
> guessing that raises red flags in terms of code quality.
>
>
> On Wednesday, January 27, 2016 at 4:43:37 PM UTC-8, Fady Shoukry wrote:
>>
>> Hey everyone,
>>
>> As the subject line suggests, I am trying to programmatically create
>> variables from a supplied dictionary in a function. I am aware that I can
>> use eval() but eval will generate global variables which is something I am
>> trying to avoid for its performance disadvantages. Here is an example of
>> what I am trying to accomplish.
>>
>> function defVariables(dict::Dict{Symbol}{Any})
>>     # This function should define the variables as follows:
>>
>>

Reply via email to