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

Feature request: list initialisation #24277

Closed
sprock opened this issue Jan 25, 2024 · 2 comments · Fixed by #24278
Closed

Feature request: list initialisation #24277

sprock opened this issue Jan 25, 2024 · 2 comments · Fixed by #24278

Comments

@sprock
Copy link

sprock commented Jan 25, 2024

Initialisation of a list using this syntax does not compile.

var lst3 : list(list(string)) = [["this", "that", "the other"],["one","two","three"]];

Summary of Problem

@lydia-duncan
Copy link
Member

Thanks for reporting! For those that didn't track the email thread, this can be worked around by writing

var lst3: list(list(string)) = new list([new list(["this", "that", "the other"]),new list(["one","two","three"])]); 

or

var lst3: list(list(string)) = [new list(["this", "that", "the other"]),new list(["one","two","three"])]; 

For the future implementer, we think making a new init= for list based off the one that takes an array would work, limiting it to only apply when the list type is a list of lists.

@jabraham17
Copy link
Member

This looks to be pretty low-hanging fruit, see the diff here: main...jabraham17:chapel:list-from-nested-array. This actually allows multiple levels of nesting, so a list(list(list(string))) works as well.

jabraham17 added a commit that referenced this issue Jan 29, 2024
This PR allows creating a `list` of `list`s from an array of arrays.
Previosuly, the following resulted in a confusing error to users.

```chapel
var a: list(list(string)) = [["a", "b"], ["c", "d"]];
```

To resolve the issue, users needed to write the following to workaround
this.

```chapel
var a: list(list(string)) = [new list(["a", "b"]), new list(["c", "d"])];
```

This PR extends the existing code that allows implicit list creation
from arrays to handled arrays and arrays, so that both of the above code
snippets work the same. This is also extendable to arrays of arrays of
arrays.

Testing
- [x] paratest without comm
- [x] paratest with comm

Resolves #24277

[Reviewed by @lydia-duncan]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants