# Anonymous function with get() misunderstanding

**URL:** <https://discourse.julialang.org/t/anonymous-function-with-get-misunderstanding/112198>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 27, 2024, 7:38pm UTC](https://discourse.julialang.org/t/anonymous-function-with-get-misunderstanding/112198 "2024-03-27T19:38:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtesseracted](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mtesseracted](https://discourse.julialang.org/u/mtesseracted)\
**Post date:** [March 27, 2024, 7:38pm UTC](https://discourse.julialang.org/t/anonymous-function-with-get-misunderstanding/112198/1 "2024-03-27T19:38:50Z")

</div>

I’m learning Julia and looking at the anonymous functions page: [Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions)  
Why does the anonymous function go as the first argument to `get` when the doc says the default parameter for an undefined key is the 3rd arg?  
[Collections and Data Structures · The Julia Language](https://docs.julialang.org/en/v1/base/collections/#Base.get)

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [March 27, 2024, 7:53pm UTC](https://discourse.julialang.org/t/anonymous-function-with-get-misunderstanding/112198/2 "2024-03-27T19:53:55Z")

</div>

Julia has special syntax for passing anonymous functions as arguments to other functions. See [Do-Block Syntax for Function Arguments](https://docs.julialang.org/en/v1/manual/functions/#Do-Block-Syntax-for-Function-Arguments).

When you write something like:

```julia
get(dict, key) do
    x = foo * bar()
    return x
end

```

Is the same as writing:

```julia
get(() -> begin
    x = foo * bar()
    return x
end, dict, key)

```

In short, `do-block` syntax is a convenient way to pass an anonymous function as argument, making code look more elegant, but with this syntax, the anonymous function will always be inserted as the **first** argument.

So, in the case of `get`, it has a method where the `default` argument is the last, but also a method where the `default` argument is the first where it should be a function, allowing you to call `get` with the convenient `do-block` syntax.

---

<div class="post-metadata">

**Author:** ![mtesseracted](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mtesseracted](https://discourse.julialang.org/u/mtesseracted)\
**Post date:** [March 27, 2024, 8:01pm UTC](https://discourse.julialang.org/t/anonymous-function-with-get-misunderstanding/112198/3 "2024-03-27T20:01:43Z")

</div>

Thanks for the quick response!  
Now I see in the `get` doc how there’s a function signature with `f::Union{Function, Type}` as the first argument.
