Simon/Mauro: thank you!
On Tuesday, March 31, 2015 at 3:35:16 PM UTC-4, Simon Kornblith wrote: > > julia> foo(;d...) > 2-element Array{Any,1}: > (:a,97) > (:b,95) > > Note the semicolon. Otherwise the Dict is splatted as positional arguments. > > Simon > > On Tuesday, March 31, 2015 at 3:29:47 PM UTC-4, Michael Turok wrote: >> >> Is there a way to pass in a dictionary for the keyword arguments that >> have a varargs specification, much like python? >> >> Note that this works in julia for passing in arrays/tuples for the >> non-keyword arguments. >> >> *julia> foo(;kwargs...) = return kwargs* >> *foo (generic function with 1 method)* >> >> *julia> foo(x=1,y=2)* >> *2-element Array{Any,1}:* >> * (:x,1)* >> * (:y,2)* >> >> *julia> d = { :a=> 97, :b => 95 }* >> *Dict{Any,Any} with 2 entries:* >> * :b => 95* >> * :a => 97* >> >> *julia> foo(d...)* >> *ERROR: `foo` has no method matching foo(::(Symbol,Int64), >> ::(Symbol,Int64))* >> >> Python example: >> >> >> >>> def foo(**kwargs): return kwargs >> ... >> >>> foo(x=1,y=2) >> {'y': 2, 'x': 1} >> >>> dict = { "a" : 97, "b" : 95 } >> >>> foo(**dict) >> {'a': 97, 'b': 95} >> >>> >> >>