# Assigning an array works in REPL but not in .jl script run from terminal

**URL:** <https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440>\
**Category:** General Usage\
**Created:** [January 12, 2017, 4:09pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440 "2017-01-12T16:09:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [January 12, 2017, 4:09pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/1 "2017-01-12T16:09:47Z")

</div>

I want to include an assignment of a multidimensional array (an array of arrays) to a variable in a script and run that script from the terminal.

I try the assignment in REPL, which works flawlessly. Assigning the first element:

> julia\> w=Array[[Array[[1.0,0.0,0.0],[0.0],[0.0],[0.0,0.0,-1.0]]]]  
> 1-element Array{Array{T,N},1}:  
> Array[[1.0,0.0,0.0],[0.0],[0.0],[0.0,0.0,-1.0]]

But when I put exactly the same syntax, namely

> w=Array[[Array[[1.0,0.0,0.0],[0.0],[0.0],[0.0,0.0,-1.0]]]]

in a .jl scrip and run it from the terminal i get

> ~/Julia/Julia\_projects/Kalman $ julia test\_vectors\_2.jl  
> WARNING: [a] concatenation is deprecated; use collect(a) instead  
> in depwarn at deprecated.jl:73  
> in oldstyle\_vcat\_warning at ./abstractarray.jl:29  
> in vect at abstractarray.jl:32  
> in include at ./boot.jl:261  
> in include\_from\_node1 at ./loading.jl:333  
> in process\_options at ./client.jl:280  
> in \_start at ./client.jl:378  
> while loading /home/philip/Julia/Julia\_projects/Kalman/test\_vectors\_2.jl, in expression starting on line 1

What is wrong?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [January 12, 2017, 4:57pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/2 "2017-01-12T16:57:18Z")

</div>

The two shows exactly the same result. You must have hit the same depwarn before so it was not printed again.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 12, 2017, 6:27pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/3 "2017-01-12T18:27:10Z")

</div>

Note that the Arrays are not completely (concretely) typed, as indicated by the parameters T, N. What happens of you remove the words “Array”?

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [January 14, 2017, 10:57pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/4 "2017-01-14T22:57:32Z")

</div>

I finally found the right syntax:

(The goal was to create a one dimensional array of arrays to which I can add alements)

This works without warnings in both REPL and run from a script in a Bash terminal:

> ```
> Testvector = Vector in e-frame lat [degreees] lon [degrees] Expected result in n-frame
> ----------------- -------------- ------------- --------------------------    
> w= Array[Array[ [1.0,0.0,0.0], [0.0], [0.0], [0.0,0.0,-1.0] ]]
> 
> ```

> Add elements to the vector  
> push!(w, [Array[[1.0,0.0,0.0], [0.0], [90.0], [0.0,-1.0,0.0] ]])  
> push!(w, [Array[[1.0,0.0,0.0], [0.0], [180.0], [0.0,0.0,1.0] ]])  
> push!(w, [Array[[1.0,0.0,0.0], [0.0], [-90.0], [0.0,1.0,0.0] ]])  
> push!(w, [Array[[1.0,0.0,0.0], [0.0], [-180.0], [0.0,0.0,1.0] ]])

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 15, 2017, 12:34am UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/5 "2017-01-15T00:34:14Z")

</div>

Are you using Julia 0.4? If so, I suggest you upgrade to 0.5.

The correct way to create an empty array of arrays of e.g. `Float64`s and then add things to it is:

```julia
julia> w = Vector{Float64}[]
0-element Array{Array{Float64,1},1}

julia> push!(w, [1.0,0.0,0.0], [0.0], [90.0], [0.0,-1.0,0.0])
4-element Array{Array{Float64,1},1}:
 [1.0,0.0,0.0]
 [0.0]
 [90.0]
 [0.0,-1.0,0.0]

```

In Julia 0.5 (but not in 0.4), you can create the array directly using the syntax that you would expect:

```julia
julia> w = [[1.0,0.0,0.0], [0.0], [90.0], [0.0,-1.0,0.0] ]
4-element Array{Array{Float64,1},1}:
 [1.0,0.0,0.0]
 [0.0]
 [90.0]
 [0.0,-1.0,0.0]

```

Note that in both cases, you do not get `Array{T,N}` (i.e. an `Array` for which the Julia compiler does not know the types contained in it), which will (usually) lead to poor performance.

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [January 15, 2017, 2:28pm UTC](https://discourse.julialang.org/t/assigning-an-array-works-in-repl-but-not-in-jl-script-run-from-terminal/1440/6 "2017-01-15T14:28:37Z")

</div>

I was on

> $ julia -v  
> julia version 0.4.8-pre

It is comforting that the syntax in Julia 0.5 is more what you would expect.

I use git for my updates and on your recommendation i did

> git branch -r  
> git checkout release-0.5  
> git pull  
> git make

Now I am on version

> $ julia -v  
> julia version 0.5.1-pre

Thanks!
