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

Enumerations with explicit strides #1087

Closed
robdockins opened this issue Feb 22, 2021 · 7 comments
Closed

Enumerations with explicit strides #1087

robdockins opened this issue Feb 22, 2021 · 7 comments
Assignees
Labels
language Changes or extensions to the language

Comments

@robdockins
Copy link
Contributor

The additional thing that might be nice is other options for specifying "down from" enumerations other than the current [n, n-1, ... 0 ] syntax. One problem with this is that n-1 requires n >= 1. Maybe something like [n .. 0 by -1 ], so you can explicitly set the stride, which is usually what you care about anyway.

Originally posted by @robdockins in #973 (comment)

@robdockins
Copy link
Contributor Author

The idea here is that it might be nice to specify the stride explicitly rather than inferring it from expressions like [n, n-1 ... 0]. In particular, this version requires that n >= 1, which might not be intended.

@yav
Copy link
Member

yav commented Feb 22, 2021

Fully agree. Not only are the types better, but I think it is more readable too. It might be nice to use a keyword or something to indicate the direction "up" or "down" to avoid having to deal with negative numbers (for the corner case where the step is a type variable)

@brianhuffman
Copy link
Contributor

Just as a datapoint: VHDL allows users to specify index ranges in either direction with the syntax (0 to 7) or (7 downto 0). (I'm not suggesting that we adopt the same syntax; it's just nice to know what other languages do when designing things like this.)

@robdockins robdockins added the language Changes or extensions to the language label Mar 3, 2021
@robdockins robdockins self-assigned this Jun 16, 2021
@robdockins
Copy link
Contributor Author

I haven't checked how this plays with the parser yet, but I'm thinking syntax like the following for expressing positive strides. This syntax would incur the obligations that x <= y and 0 < n.

[ x .. y by n ]
[ x .. < y by n ]

Here the edge case is a bit more subtle than with n = 1. With the [ x .. y by n] syntax, y will only be included if (y-x) is divisible by n (or is 0). As with the n = 1 case, y will never be included with [x ..< y by n].

For descending sequences, I'm less sure what we want exactly. Which of the following possible variations would we want?

[ x .. y down by n ]
[ x> .. y down by n ]
[ x .. >y down by n]
[ x> .. >y down by n]

I suppose we could also have these, for infinite sequences.

[ x ... by n]
[ x ... down by n]

@robdockins
Copy link
Contributor Author

Thinking about it some more, the [ x> .. >y ] variant is underspecified and doesn't make much sense. Moreover [ x> .. y down by n] would just be reverse [ y .. <x by n] so maybe it's less interesting.

@robdockins
Copy link
Contributor Author

Playing with the parser a bit, it seems like we'll need to make by and down keywords if we want this syntax to work. Are those identifiers too valuable to steal for this purpose?

@robdockins
Copy link
Contributor Author

Fixed via #1227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes or extensions to the language
Projects
None yet
Development

No branches or pull requests

3 participants