lambda
lambda copied to clipboard
Disallow negative integers as indices
Currently, int
is allowed as index for indexed types (arrays and strings). The reason we can't restrict this to uint
is that we want to be able to use expressions like - n 1
as indices. The current implementation of the -
operator types to int
even if both operands are uint
because the result of a subtraction may be negative.
A possible solution is to implement proper 32- or 64-bit unsigned integers and wrap around when a negative value is produced, but this would raise the problem of deciding the width. A possible solution to this would in turn be to provide both 32-bit and 64-bit integer types.
Another possible solution is to default to 32-bit width on 32-bit platform and 64-bit width on 64-bit platforms, but this would make it difficult handling 64-bit values on 32-bit platforms.
Based on #77, wrapping integer values is no longer an option. Numeric types must now reflect the numeric sets used in math.
Another option would be to implement semi-circular arrays, like in Python; negative indices would refer to elements from the end (i.e. -1
refers to the last element, -2
to the second-last, etc.). This would justify integer indices.