# How to do it remake

**URL:** <https://discourse.julialang.org/t/how-to-do-it-remake/26500>\
**Category:** New to Julia\
**Created:** [July 18, 2019, 1:53pm UTC](https://discourse.julialang.org/t/how-to-do-it-remake/26500 "2019-07-18T13:53:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![1112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1112/32/9325_2.png) [@1112](https://discourse.julialang.org/u/1112)\
**Post date:** [July 18, 2019, 1:53pm UTC](https://discourse.julialang.org/t/how-to-do-it-remake/26500/1 "2019-07-18T13:53:50Z")

</div>

```julia
	IssetX = function(ArX,x)
		indexX = true
		try
			indexX = getindex(ArX, x)
		catch
			indexX = false
		end	
		indexX
	end	
ArX = Dict(542=>1,566=>2)
IssetX(ArX,550)

```

x may not be in ArX, I just make an exception, maybe there is a more competent option?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [July 18, 2019, 2:00pm UTC](https://discourse.julialang.org/t/how-to-do-it-remake/26500/2 "2019-07-18T14:00:37Z")

</div>

First, when you declare functions that way, they are technically anonymous. I believe that accessing functions declared in global scope this way is inefficient, so you usually want to avoid this unless you really intend to to use an anonymous function bound to `IssetX`.

`Base` has the function `get`, which lets you define a default if the argument is not found as a key. For example

```julia
get(Arx, x, y)

```

This will return `ArX[x]` if `x \in keys(ArX)` else it will return `y`.

```julia
get!(ArX, x, y)

```

will do the same except it will also add `y` as the value of key `x` if `x` is not already a key.

---

<div class="post-metadata">

**Author:** ![1112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1112/32/9325_2.png) [@1112](https://discourse.julialang.org/u/1112)\
**Post date:** [July 18, 2019, 2:06pm UTC](https://discourse.julialang.org/t/how-to-do-it-remake/26500/3 "2019-07-18T14:06:55Z")

</div>

> [@ExpandingMan](#):
>
> get(Arx, x, y)

thank you! How it all just turns out)
