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

Introduce square brackets as an alternative syntax for sublist access #5765

Closed
wants to merge 1 commit into from

Conversation

zickgraf
Copy link
Contributor

This makes it easier to share code between GAP and Julia, for example:

gap> ["a", "b", "c"][[3, 1]];
[ "c", "a" ]
julia> ["a", "b", "c"][[3, 1]]
2-element Vector{String}:
 "c"
 "a"

I post this as a draft because I expect this to be controversial. If the change is welcome, I will of course add documentation and tests :-)

Text for release notes

see title

@ChrisJefferson
Copy link
Contributor

Does this actually usefully help unify Julia and GAP? I'd assume there would be a lot more differences between them?

This might conflict (or at least complicate) some packages. For example HomalgRing.gd already installs an 'IsList' for IsHomalgRing and IsList.

If your concern is that people might try l[[2,3]], and get confused by the output, you could do what we do for "a" + "b" and put a very lowly ranked method which prints an error, and points to what people should use instead.

@fingolfin
Copy link
Member

I am not a fan. If we were creating GAP from scratch these days, perhaps; but we aren't.

  • as a heavy GAP and heavy Julia user, I don't really see the benefit. There are so many other differences I stumble over far more often when switching (semicolons; different assignment/comparison operators; if requiring then or not; etc.)
  • There is existing code that interprets a[[i,j]] as a[i,j] so there is a semantic clash.
  • There is already an established GAP syntax for this which is strictly more powerful and so for a regular GAP user there is no advantage
  • each new feature complicates the language as it requires users to learn about it. Long time GAP users will be puzzled by it. This can be worth it, but I just don't see the general benefit here.

@zickgraf
Copy link
Contributor Author

@ChrisJefferson @fingolfin Thanks for your feedback! I see that for GAP the problems outweigh the potential benefits, so I will close the PR.

Some additional background: Some of our CAP code can be easily translated to Julia using simple string replacements (for example, fi -> end). Of course this PR does by far not make everything compatible, but since every little bit helps, I thought I would try to propose this :-)

@zickgraf zickgraf closed this Jul 24, 2024
@zickgraf zickgraf deleted the sublist branch July 24, 2024 11:27
@zickgraf zickgraf restored the sublist branch July 24, 2024 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants