# Atom doesn't run called function correctly

**URL:** <https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873>\
**Category:** New to Julia\
**Tags:** question, repl, error\
**Created:** [June 3, 2019, 5:28am UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873 "2019-06-03T05:28:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [June 3, 2019, 5:28am UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/1 "2019-06-03T05:28:57Z")

</div>

I am trying to run [JuliaMatrixBenchmark.jl](https://github.com/aminya/MatlabJuliaMatrixOperationsBenchmark/blob/master/JuliaMatrixBenchmark.jl) and [JuliaMatrixBenchmark0001.jl](https://github.com/aminya/MatlabJuliaMatrixOperationsBenchmark/blob/master/JuliaMatrixBenchmark0001.jl) from the repository [MatlabJuliaMatrixOperationsBenchmark](https://github.com/aminya/MatlabJuliaMatrixOperationsBenchmark), that I forked from an old repository for comparing MATLAB and Julia, and edited files to update its Julia language.  
However, in Atom when I run the master script from the file [JuliaMatrixBenchmark.jl](https://github.com/aminya/MatlabJuliaMatrixOperationsBenchmark/blob/master/JuliaMatrixBenchmark.jl), it gives me strange errors such as temp is not defined. However, if I copy paste the code into REPL it works with no issues. Where is the problem?

Edit: if you are reading this post later: I replaced those files with new ones in the repository which is available here: [MatlabJuliaMatrixOperationsBenchmark](https://github.com/aminya/MatlabJuliaMatrixOperationsBenchmark)

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [June 3, 2019, 6:01am UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/2 "2019-06-03T06:01:36Z")

</div>

I think you should try to paste a minimum working example so that helping you is easier. We will not be able to get very far or to see that your function calls are correct.

However, it sounds to me like you hit a scoping problem. Is there any variable called “temp” that you are trying to update inside a for-loop? try writing `global temp` inside the for but before trying to update that variable.

Edit:

Apparently the problem is that @benchmark cannot see the local scope, it only sees the global (this I don’t know why).  
If you add `global temp = cRunTimeFunctions[jj]` it will work, although I don’t know if that’s the right way to do it. The reason for it working in the REPL is that the REPL works in the global scope. This [scoping rules](https://docs.julialang.org/en/v1/manual/variables-and-scoping/index.html) can be a good place to look at when something works at the REPL but not elsewhere.

In line 110 you have `trnasposed` instead of `transposed`  
In line 117 you need to use the word `dims`, like `mA = sum(mX, dims=1) .+ minimum(mY, dims=2)`

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 3, 2019, 8:41am UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/3 "2019-06-03T08:41:26Z")

</div>

Not sure what makes you think that this is an issue with Atom running your code and not with your code. Compare e.g.

```julia
julia> let tmp = sin
           @benchmark tmp(1.2)
       end
ERROR: UndefVarError: tmp not defined

julia> let tmp = sin
           @benchmark $tmp(1.2)
       end

```

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [June 3, 2019, 3:16pm UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/4 "2019-06-03T15:16:42Z")

</div>

Defining _temp, matrixSize, mX, mY_ as global solved the issue. However, this is very strange, I don’t understand why I should do this! Is it because of _@benchmark_?

BTW, thank you for finding the typos. Unfortunately, Atom doesn’t have any code analyser (or it doesn’t work for me).  
I updated the repository for this file.

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [June 3, 2019, 3:19pm UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/5 "2019-06-03T15:19:12Z")

</div>

Adding $ doesn’t help.  
P.S: _I have started with Julia for 1 week, and I asked my question in First steps section, so don’t blame me for not being familiar with these strange problems that may occure._

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [June 3, 2019, 3:35pm UTC](https://discourse.julialang.org/t/atom-doesnt-run-called-function-correctly/24873/6 "2019-06-03T15:35:30Z")

</div>

Yeah, this is apparently part of the design choices of `BenchmarkTools`.

From [the documents here](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md):

```julia
Normally, you can't use locally scoped variables in @benchmark or @benchmarkable, since all benchmarks are defined at the top-level scope by design. However, you can work around this by interpolating local variables into the benchmark expression:

# will throw UndefVar error for `x`
julia> let x = 1
           @benchmark sin(x)
       end

# will work fine
julia> let x = 1
           @benchmark sin($x)
       end

```

Also, as your matrices are also defined in the local scope, you might want to call the function as `@benchark temp($matrixSize,$mX,$mY)` (adding a ‘’$') to make the benchmarks more accurate.

P.s for me it worked with adding `global temp` before using it, without making _matrixSize, mX, mY_ globals.
