El miércoles, 11 de febrero de 2015, 15:44:46 (UTC-6), Simon Danisch 
escribió:
>
> How about simply iterating over the dict?
>
> for (key, value) in dict
>     set(simulation, key, value)
> end
> Note, that you can actually access a type like this:
> type T 
> a::Int
> end 
> x = T(1)
> x.(:a) = 10 #<- :a is a symbol, which can be created like this 
> symbol("string")
> x.(:a) is equivalent to getfield(a, :a)
>

OK, thanks.

I think what was worrying me was having a dict with strings as keys. Is the 
following a sensible way to convert to a dict with symbols as keys?

julia> d = {"a" => 10}
Dict{Any,Any} with 1 entry:
  "a" => 10

julia> d2 = {symbol(s)=>d[s] for s in keys(d)}
Dict{Any,Any} with 1 entry:
  :a => 10

David
 

>
> For function calls, tshort has the answers ;)
> Besides you can do stuff like:
> func(values(dict)...)
> if you want to call a function with the values from the dict, which is a 
> little problematic due to the order.
>
> Am Mittwoch, 11. Februar 2015 21:25:22 UTC+1 schrieb David P. Sanders:
>>
>> Hi,
>>
>> If I have a dictionary
>>
>> params = {"N": 10, "M": 2.0}
>>
>> how can I use it to define two variables N and M with the corresponding 
>> values?
>>
>> This sounds like it should be easy and obvious, say using `eval`?
>> E.g. extract the keys and values into strings and then use
>>
>> eval(parse("N=10"))
>>
>> Is this reasonable?
>>
>> The use case is to load input parameters for a simulation. Maybe there is 
>> a better way? 
>>
>> Thanks,
>> David.
>>
>

Reply via email to