How to avoid negative index in [] or [range]

I think it is not a good idea to support negative numbers in or [range]

For example, Julia uses [end-1] and Nim uses [^1] to avoid this.

So why do you think it’s not a good idea? What needs to be avoided?

  • Error when index is negative
  • Simple version of [a.size-1] for reverse index except negative index (may need compiler support, just a side note, you can ignore it)
2 Likes

So why do you think it’s not a good idea? What’s the reasoning for wanting to avoid it? Because other languages don’t support it?

I assume the idea of aiac is to catch possible errors for off-limits indices. That is, make -1 an error instead, so any mistake in calculations is caught, instead of working with a “”“unexpected”“” result.

2 Likes

Marked as solved. No other answers expected.