Arithmetic on Ranges

Viewed 58

If I have a UnitRange, how can I add/shift/translate the values?

Say I have 1:3

And I want 2:4?

1:3 + 1 gives me 1:4, as does 1:3 .+ 1

1 Answers

The : operator has lower precedence than the arithmetic operators, so your two expressions are equivalent to 1:(3 + 1) and 1:(3 .+ 1). Try this:

julia> 1 .+ (1:3)
2:4
Related