Alec
Alec

Reputation: 4472

Arithmetic on Ranges

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

Upvotes: 3

Views: 65

Answers (1)

Cameron Bieganek
Cameron Bieganek

Reputation: 7664

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

Upvotes: 8

Related Questions