Should mutableSublist not be required to support mutation operations for changing size? #402
AlexKnauth
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What should the
mutableSublistmethod on mutable lists produce?If the hierarchy of list interfaces looks something like this:
ReadableListreading operations: elements, unmodifiable sublistsListfunctional operations including changing sizeMutableListmutation operations including changing sizeThen it seems like any mutable list implementation would have to have to make
mutableSublistproduce aMutableListthat supports mutation operations that can change the size, such as appending, prepending, inserting, and removing.But for many mutable list implementations, it wouldn't make sense to do this. Instead, it might make more sense for their
mutableSublistto produce a "slice", like Rust's&mut [T], that does not support operations that can change the size.So should a new interface be inserted between
MutableListandReadableListwhich doesn't support those operations that can change the size?ReadableListreading operations: elements, unmodifiable sublistsListfunctional operations including changing sizeIndexMutableListmutation operations by existing index only, NO changing sizeMutableListmutation operations including changing sizeReadableListmethodsublistproducesReadableList:and can produce
Listif desired.ReadableList,and should NOT produce
IndexMutableListorMutableList.IndexMutableListmethodmutableSublistproducesIndexMutableList:IndexMutableList,but does not have to implement
MutableList.Fixed-length mutable lists such as Racket's
vectorshould implementIndexMutableListbut notMutableList.Flexible-length mutable lists such as Racket's
gvectorshould implementMutableList.I expect most mutable list implementations will choose to make
mutableSublistproduce onlyIndexMutableList, notMutableList.There's nothing stopping a mutable list implementation that wants to override
mutableSublistto produce aMutableListwith the "appending to the sublist inserts into the middle of the backing list" behavior, but this way it wouldn't be mandatory.Beta Was this translation helpful? Give feedback.
All reactions