It's just a function so it must evaluate all its arguments. With the exception of a few built-in special forms like ccall, if something looks like a function call in Julia, it is a function call. In particular, macro invocations, which can introduce radically different semantics, do not look the same. There is higher-order method of get that takes a zero-argument function and does what you want:
get(dict1,1) do get!(dict2,1,2) end There's been discussion about adding syntax for dictionaries in the past, but we never settled on anything. On Sun, Apr 6, 2014 at 9:57 AM, Adam Kapor <[email protected]> wrote: > Is get supposed to evaluate the fallback argument? I was surprised by > this: > > julia> dict1 = {1=>1} > {1=>1} > julia> dict2 = Dict() > Dict{Any,Any}() > julia> get(dict1,1,get!(dict2,1,2)) > 1 > julia> dict2 > {1=>2} > > The other method is more what I'd have expected > julia> get(dict1,1) do > ()->get!(dict2,1,2) > end > 1 > julia> dict2 > Dict{Any,Any}() > > >
