# Refer to variables by a different name

**URL:** https://discourse.julialang.org/t/refer-to-variables-by-a-different-name/88162
**Category:** New to Julia
**Created:** [October 3, 2022, 2:15pm UTC](https://discourse.julialang.org/t/refer-to-variables-by-a-different-name/88162 "2022-10-03T14:15:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://discourse.julialang.org/u/james3)
#### Post date: [October 3, 2022, 2:15pm UTC](https://discourse.julialang.org/t/refer-to-variables-by-a-different-name/88162/1 "2022-10-03T14:15:52Z")

</div>

I pass a struct (containing pre-allocated arrays for intermediate calculations) to many different functions. My struct looks something like this

```julia
struct Workspace
    fN_1::MVector{N, Float64}
    fN_2::MVector{N, Float64}
    fM_1::MVector{M, Float64}
    iM_1::MVector{M, Int64}
end

```

where `N` and `M` are compile time constants. This works well, but the code does lose readability as the variable names cease to be meaningful: in one function, `fN_1` may be time in an intermediate calculation, and in another function it may measure something completely different. Is it possible to refer to a variable by a different name in some local scope?

So, rather than doing

```julia
function myfun(w::Workspace, x)
	...
	for i = 1:N
		w.fN_1[i] = ...
	end
	...
        (some calculation using w.fN_1)
end

```

I first tell Julia that I want to use a different name, so do something like

```julia
function myfun(w::Workspace, x)

	elapsed_time => w.fN_1

	...
	for i = 1:N
		elapsed_time[i] = ...
	end
	...
        (some calculation using elapsed_time)
end

```

Thanks.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 3, 2022, 2:33pm UTC](https://discourse.julialang.org/t/refer-to-variables-by-a-different-name/88162/2 "2022-10-03T14:33:40Z")

</div>

I’m not sure I fully understand your question, as you ask about variables but your examples are about the names of fields in a struct.

Your second example should work fine if you use `=` for assignment

```julia
function myfun(w::Workspace, x)
    elapsed_time = w.fN_1
    ....
end

```

assignment doesn’t copy in Julia so this doesn’t cost you anything.

When you ask about “refer[ing] to a variable by a different name in some local scope” that sounds like a `let` block:

```julia
julia> x = 5
5

julia> let a = x
           println(a)
       end
5

```
