# $a as argument to function

**URL:** <https://discourse.julialang.org/t/a-as-argument-to-function/12386>\
**Category:** General Usage\
**Created:** [July 15, 2018, 8:52am UTC](https://discourse.julialang.org/t/a-as-argument-to-function/12386 "2018-07-15T08:52:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferran\_Mazzanti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ferran_mazzanti/32/7458_2.png) [@Ferran\_Mazzanti](https://discourse.julialang.org/u/Ferran_Mazzanti)\
**Post date:** [July 15, 2018, 8:52am UTC](https://discourse.julialang.org/t/a-as-argument-to-function/12386/1 "2018-07-15T08:52:47Z")

</div>

Hi folks,  
just a (probably) stupid question here. In another thread I’ve seen that people is testing functions operating on arrays, such that when the function is called, the array name is preceded by the $-symbol

```julia
function koly(x)
...
end

a=rand(10000);
@time koly($a)

```

and the result of the calculation seems to be fast, does no allocation and so there is garbage collection… looks perfect 🙂  
Now I don’t know how these things are related because I can’t find the meaning of this $-syntax anywhere. Can somebody tell me/point me to the right documentation about this? Is it a feature of Julia 0.7? I ask becaus eI’m running 0.6.4, have tried it and the compiler complains

```julia
koly($a)

unsupported or misplaced expression $

```

Thanks in advance,

Ferran.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [July 15, 2018, 8:57am UTC](https://discourse.julialang.org/t/a-as-argument-to-function/12386/2 "2018-07-15T08:57:31Z")

</div>

That is called “interpolation”, what happens is an expression is basically spliced or inserted into the code at that point, so that instead of referencing that value, it is directly inserted.

[https://docs.julialang.org/en/stable/manual/metaprogramming/#Interpolation-1](https://docs.julialang.org/en/stable/manual/metaprogramming/#Interpolation-1)

It works when an `Expr` or `String` is constructed, but not otherwise. Macros operate on expressions, so it works there, but it doesnt work in the REPL if you are not working with expression object or macros or strings.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [July 15, 2018, 10:16am UTC](https://discourse.julialang.org/t/a-as-argument-to-function/12386/3 "2018-07-15T10:16:10Z")

</div>

That’s a feature of [BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl#quick-start):

> If the expression you want to benchmark depends on external variables, you should use $ to “interpolate” them into the benchmark expression to avoid the problems of benchmarking with globals. Essentially, any interpolated variable x or expression (…) is “pre-computed” before benchmarking begins:
> 
> julia\> A = rand(3,3);
> 
> julia\> @btime inv($A); # we interpolate the global variable A with $A  
> 1.191 μs (10 allocations: 2.31 KiB)
> 
> julia\> @btime inv($(rand(3,3))); # interpolation: the rand(3,3) call occurs before benchmarking  
> 1.192 μs (10 allocations: 2.31 KiB)
> 
> julia\> @btime inv(rand(3,3)); # the rand(3,3) call is included in the benchmark time  
> 1.295 μs (11 allocations: 2.47 KiB)

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [July 15, 2018, 2:50pm UTC](https://discourse.julialang.org/t/a-as-argument-to-function/12386/4 "2018-07-15T14:50:59Z")

</div>

Another way of saying this: the $ interpolates the value of `a` into the expression `:(kern($a))` so that the benchmarking code can avoid the performance penalty associated with looking up the global variable `a`.

You don’t need to worry about this in your code as long as you follow [Performance Tips · The Julia Language](https://docs.julialang.org/en/v0.6.1/manual/performance-tips/#Avoid-global-variables-1)
