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

IsList for the results of Slice? #114

Open
ThomasBreuer opened this issue Mar 20, 2019 · 5 comments
Open

IsList for the results of Slice? #114

ThomasBreuer opened this issue Mar 20, 2019 · 5 comments

Comments

@ThomasBreuer
Copy link
Contributor

Is it necessary that slices are in the filter IsList?

  • Currently comparing a plain list and a slice with the same entries w.r.t. \= yields false,
    due to the different families, which contradicts the definition of \= for lists.
  • Non-dense slices are apparently supported. If a slice has a hole in the last position
    then the Length value does not correspond to the last bound position.
    If slices would not be in IsList then these would be just features of slices, not inconsistencies.
@ChrisJefferson
Copy link
Member

I agree this is not perfect.

I wanted to be able to run functions like Sort, Minimum and various list accessing functions on slices, which require (I think) I support IsList.

However, the \= being wrong is particularly worrying. The non-denseness I could try to return a proper length.

If there was a nice way i could call Sort and Minimum on slices without being IsList, I'd be very happy to do that.

@ThomasBreuer
Copy link
Contributor Author

As far as I understand, it is anyhow necessary to write specific code for sorting slices etc.,
that is, one cannot use GAP's generic methods for lists.
Thus it would be possible to remove the IsList filter from slices, and to install the relevant methods, using InstallOtherMethod.
The point is that on the one hand, one gets list-like functionality for slices this way, and on the other hand one gets more freedom in the sense that objects which are not in IsList are not required to obey GAP's global rules for lists.

@ChrisJefferson
Copy link
Member

So at the moment, all sorts of list functions work "fine" on slices, for example:

gap> p := [1,2,3,4,5,6,7,8];
[ 1, 2, 3, 4, 5, 6, 7, 8 ]
gap> s := Slice(p, 3, 3);
[ 3, 4, 5 ]
gap> Sort(s);
gap> s;
[ 3, 4, 5 ]
gap> Minimum(s);
3
gap> Maximum(s);
5
gap> List(s, x -> x^2);
[ 9, 16, 25 ]

@ThomasBreuer
Copy link
Contributor Author

I think the point is what you want to achieve.

If slices are intended as an alternative representation for general lists in GAP, with all list functionality, then slices should be in IsList, and then they have to obey the rules for lists.
This starts with choosing the appropriate family and filters. For example, a slice of a non-homogeneous list may be homogeneous, a slice of a non-dense list may be dense, and so on. Setting and adjusting the right type then requires some work.
On the other hand, one gets some generic list functionality for free, such as Maximum or Minimum.
(One does not get Sort for free.)

If slices are intended as some special purpose data structure for doing certain things efficiently then I think the rules for lists are a burden for the slice objects.
Of course one can decide that some list functionality is useful for slices, and then one has to install a method for it.

@ChrisJefferson
Copy link
Member

So, I have fixed Length, but I haven't looked at Equal yet.

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

No branches or pull requests

2 participants