# Understanding how to declare a function and store it inside another variable for later use

**URL:** <https://discourse.julialang.org/t/understanding-how-to-declare-a-function-and-store-it-inside-another-variable-for-later-use/76144>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [February 10, 2022, 5:53am UTC](https://discourse.julialang.org/t/understanding-how-to-declare-a-function-and-store-it-inside-another-variable-for-later-use/76144 "2022-02-10T05:53:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirror63](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mirror63](https://discourse.julialang.org/u/mirror63)\
**Post date:** [February 10, 2022, 5:53am UTC](https://discourse.julialang.org/t/understanding-how-to-declare-a-function-and-store-it-inside-another-variable-for-later-use/76144/1 "2022-02-10T05:53:18Z")

</div>

```julia
histogram(x[1000:end], norm=true, label=["Empirical distribution"])
xGrid = -4:0.1:4
pdfnormalDensity(z) = pdf(Normal(0,1),z)
pdf_normal=pdfnormalDensity.(xGrid)
plot!(xGrid, pdf_normal, xlims=(-4,4), label=["Normal pdf"])

```

Can someone explain me the code here? I understand that we are creating a normal distribution of mean 0 and standard deviation 1, and we are drawing a histogram and a normal graph of the axis from -4 to 4. However, my question is `pdfnormalDensity(z) = pdf(Normal(0,1),z)` , can someone explain z and what is z doing here, and then what happens in pdfnormalDensity(z)? Thanks

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [February 10, 2022, 6:15am UTC](https://discourse.julialang.org/t/understanding-how-to-declare-a-function-and-store-it-inside-another-variable-for-later-use/76144/2 "2022-02-10T06:15:53Z")

</div>

You can improve the legibility of your code by using a triple backtick fence:

````julia
```
like this
```

````

If you’re ever uncertain about what a function does, or what arguments you can give it, try pressing `?` in a REPL, which will get you to the help-mode. Then write the name of the function, and you will see the docstrings.

In this case, you are defining a function `pdfnormalDensity(z)` which gives the value at `z` of the probability density function for a normal distribution.

---

<div class="post-metadata">

**Author:** ![mirror63](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mirror63](https://discourse.julialang.org/u/mirror63)\
**Post date:** [February 10, 2022, 7:07am UTC](https://discourse.julialang.org/t/understanding-how-to-declare-a-function-and-store-it-inside-another-variable-for-later-use/76144/3 "2022-02-10T07:07:12Z")

</div>

thank you so much for the information. I saw the docstrings however, was confused what was going on, now it makes sense thanks. 🙂
