As Micheal pointed out, think very carefully about why you need this 
behaviour because it will leak variables into the global scope which is 
currently a very bad idea in Julia.

On Sunday, 15 February 2015 22:46:56 UTC, Martin Johansson wrote:
>
> Thanks, the second solution was what I was looking for!
>
> Regards, m
>
> On Sunday, February 15, 2015 at 11:41:02 PM UTC+1, Sean Marshallsay wrote:
>>
>> I'm not too certain what you're asking here.
>>
>> Do you mean something like this:
>>
>> julia> d = Dict()
>> Dict{Any,Any} with 0 entries
>>
>> julia> for i in [:var1, :var2, :var3]
>>            d[i] = string(i)
>>        end
>>
>> julia> d
>> Dict{Any,Any} with 3 entries:
>>   :var3 => "var3"
>>   :var1 => "var1"
>>   :var2 => "var2"
>>
>> Or something more like this:
>>
>> julia> d = [:a=>1, :b=>2, :c=>3]
>> Dict{Symbol,Int64} with 3 entries:
>>   :b => 2
>>   :c => 3
>>   :a => 1
>>
>> julia> for (k,v) in d
>>         @eval $k = $v
>>        end
>>
>> julia> a
>> 1
>>
>> julia> b
>> 2
>>
>> julia> c
>> 3
>>
>> Or maybe something else entirely?
>>
>> On Sunday, 15 February 2015 22:17:54 UTC, Martin Johansson wrote:
>>>
>>> Is there a way to "assign" the values of a Dict to the corresponding 
>>> keys such that I get "variables" (symbols?) with names given by the keys? 
>>> Let's assume the keys are for example strings which would work as variables.
>>>
>>> The reason for why I would want to do this is to have functions where 
>>> explicit variables are used rather than Dicts, primarily for readability. 
>>> I'm suspecting that this is not a recommended way of doing things (since I 
>>> couldn't find any info along these lines when searching), and if this is 
>>> the case please set me straight.
>>>
>>> Regards, m
>>>
>>>
>>>

Reply via email to