Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow negative integers as indices #74

Open
71104 opened this issue Apr 29, 2016 · 2 comments
Open

Disallow negative integers as indices #74

71104 opened this issue Apr 29, 2016 · 2 comments

Comments

@71104
Copy link
Owner

71104 commented Apr 29, 2016

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.

@71104
Copy link
Owner Author

71104 commented Apr 29, 2016

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.

@71104
Copy link
Owner Author

71104 commented May 15, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant