AutoSized Array Bounds in Declarations

The declaration

const x = [ 1, 2, 3, 4, 5 ];

autoaticallt figures out the dimensions of x but mandates a lower bound of 0

It would be useful if the following syntax (using a legal range) was legal:

const x : [0..] int = [ 1, 2, 3, 4, 5];

This would then allow declarations like

const x : [1..] int = [ 1, 2, 3, 4, 5];

for those of us who work with arrays that are not always 0-based.

Neither urgent nor critical. Thanks

1 Like

Hello Damian,

Good suggestion. In cases like this it is great to create an issue requesting this feature, at Sign in to GitHub · GitHub

Another way to achieve this result could be:

const x = [ 1, 2, 3, 4, 5 ].reindex(1..);

Until this is supported officially, I could put together a patch to our modules or a standalone helper function that does this, if you'd like.


I will put together a Github issue but I wanted to get some feedback first just in case it was a silly idea I thought about reindex but it is far less obvious.

There is no rush. Very low priority, No need for a temporary solution.

1 Like

Hi Damian and Vass —

To save some trouble, note that there's already an issue for this request here: Support inferred-size arrays via partially bounded ranges · Issue #10596 · chapel-lang/chapel · GitHub. Rather than posting a new one, Damian could comment on this one indicating his interest.

FWIW, I am a big fan of this feature,

[edit: Whoops, just caught up enough to see that my suggestion was too late: AutoSized Array Bounds in Declarations · Issue #24440 · chapel-lang/chapel · GitHub]

I will delete mine. I went searching prior to my posting but never turned up that old issue. My search skills suck. :wink:

1 Like