# Using eval to evaluate a variable inside an expression when string interpolation is not ok

**URL:** <https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356>\
**Category:** General Usage\
**Tags:** arrays, eval, functions\
**Created:** [June 7, 2022, 3:27am UTC](https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356 "2022-06-07T03:27:37Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 8, 2022, 5:56am UTC](https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356/6 "2022-06-08T05:56:24Z")

</div>

> [@mikeliux](#):
>
> `A=[[1,2,3] [4,5,6]]`

Note that you can also do `A = [1 4; 2 5; 3 6]` instead of first constructing 1d arrays and concatenating them.

> [@mikeliux](#):
>
> I am trying to create a function to shuffle an n-dimensional array `X` along a desired dimension

You can use

```julia
julia> using Random # for shuffle

julia> mapslices(shuffle, A, dims=1)
3×2 Matrix{Int64}:
 2 5
 3 4
 1 6

```

Metaprogramming (generating code) can be a powerful tool, but it’s also a specialized one that is used rarely in practice — it’s not something I would typically recommend for starting users. See [How to warn new users away from metaprogramming - #22 by stevengj](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/22)

---

_[View the full topic](https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356)._
