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

Strange list cast #3803

Closed
lesquoyb opened this issue May 5, 2023 · 2 comments
Closed

Strange list cast #3803

lesquoyb opened this issue May 5, 2023 · 2 comments
Assignees
Labels
About GAML This issue concerns the GAML language 👍 Fix to be tested 🤔 Question
Milestone

Comments

@lesquoyb
Copy link
Collaborator

lesquoyb commented May 5, 2023

Describe the bug
casting something into a list returns unexpected behaviours:

list("few words");

returns an empty list instead of a list containing the string "few words" or the list of characters that compose it.
Even stranger is:

list([1::2]);

this expression returns [2], which to me is the least obvious result, it could be either [1,2] or [1::2] but a list containing only 2 makes no sense from the user's point of view (though I understand it's the pair's value).
What is even stranger is that:

list(pair(1::2));

returns [1::2], why do we have to explicitly cast the pair into a pair while it's declared with a literal ?

@lesquoyb lesquoyb added 🤔 Question About GAML This issue concerns the GAML language labels May 5, 2023
@AlexisDrogoul
Copy link
Member

  1. I've addressed the issue with strings (it was a mistake on a tokenizer). It now correctly returns the list of characters (i.e. ["f", "e",...])
  2. The problem comes from the fact that, by default, a map returns its list of values when casted to a list. And [1::2] is a map, not a pair. If you write list(1::2) instead, it will return: [1,2]. Better not to change this behavior, as iterations on maps values rely on it !

@lesquoyb
Copy link
Collaborator Author

Ok, waiting for your commit to close then.
The second point makes me think that we may need to have stricter rules to define list/map (and others?) literals in GAMA 2 then, so [] would be strictly for list and {} strictly for maps for example. So as to avoid that kind of confusion (at least it would print a warning that it's going to be casted)

AlexisDrogoul added a commit that referenced this issue May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
About GAML This issue concerns the GAML language 👍 Fix to be tested 🤔 Question
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants