Skip to content

markmbaum/MultiAssign.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiAssign.jl

Build Status Coverage

MultiAssign exports a macro for assigning a value/expression to multiple variables in a single terse and clear line. For example, you can write

@multiassign x, y, z = zeros(n)

instead of

x = zeros(n)
y = zeros(n)
z = zeros(n)

or

x, y, z = (zeros(n) for _ in 1:3)

Importantly, each of the variables is assigned with a distinct call to zeros in the example above. The resulting x, y, and z vectors are not copies of each other.

The macro should work wherever multiple variables should be assigned the same value. It simply generates identical assignments for each variable.

Type annotations will also work if you need them, except in global scope. For example

@multiassign a::Float64, b::Float32, c::Int64 = 0

will work inside a function, but not at the global scope of the REPL.

About

Assign the same value/expression to multiple variables with one terse and clear line

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages