Looking at the get function of base Julia, it is apparently intended to be used using a do-block:
get(dict, key) do
# default value calculated here
time()
end
The signature for get is get(Dictionary_name, Key_name, Default Value). This means that the do-block automatically inserts the default value as the last argument of get.
When I compare this syntax for the do-block with the one in this thread, I notice a difference:
my_function(f, container) = begin
for element in container
f(element)
end
return nothing
end
my_function([1,2,3]) do x # equivlent to my_function(print, [1,2,3])
print(x)
end
Notice how the function f is the very first argument of my_function, so the do-block inserts print as the first argument of my_function, not the last.
This is my confusion: Why is it that the do-block in one example inserts the variable as the last argument, but in another inserts in as the first?