Refer to variables by a different name

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

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

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

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.

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

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> x = 5
5

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