-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: Refactor List to use Rep<Obj> internally
#172
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
Conversation
|
@dgkf To allow for this refactor I think the I am wondering though whether there was a specific reason why the R/src/object/vector/subsets.rs Line 9 in ee9b4a4
Subset::Names (Line 19 in ee9b4a4
|
Yeah, this part isn't as clean as I'd like. It could definitely benefit from a rework. If a subset only operates on indices, then we can collapse multiple subsets into a set of indices pretty easily - These two structures serve different purposes.
These are poorly named and conceptually I'm not crazy about how I modeled the problem. It exists this way because I built the subset altrep while completely neglecting named subsets and only realized after the rest of the proof-of-concept was put together 😬. If the feature looks tacked on, that's because it totally was. |
|
Just fyi: My vacation is starting on Friday and I am planning to resume working on this! |
|
Uff, so I think I started something here before properly understanding it. The changes here basically allow One idea I had is whether we maybe want to add a This would:
I am not sure whether this is fully necessary now and maybe there is a better way to approach this. What do you think? |
Let me make sure I'm understanding you correctly here. The proposal is to store names in representation instead of in the Just from the perspective of how this abstracts the problem, I feel like this sort of conflates a couple ideas. If we still want a named object to be able to behave like an unnamed object, then having two separate variants here that have largely overlapping behaviors feels like it might not be modelling the problem as effectively as it could be. What about something like: RepType<T> {
Subset(CowObj<Vec<T>>, Option<..>, Subsets)
}Where |
|
Yeah, I think this is better, I will try it out. |
|
Another positive side effect of refactoring this is that it forces us to implement the behavior of lists and vectors consistently. Assigning l = list(1, 2, 3, 4)
l[1:2] = NULL
l
#> [[1]]
#> [1] 3
#>
#> [[2]]
#> [1] 4
l[[1]] = NULL
l
#> [[1]]
#> [1] 4While I find it somewhat reasonable that assigning Furthermore, I would even argue against the semantics of the slice-assignment to NULL ( v = 1:3
v[1:2] = NULL
#> Error in v[1:2] = NULL: replacement has length zeroFor the scenario where one wants to remove specific elements from a list/vector, we can (in the future, see #169) achieve this with negative indices. However, for named lists / vectors there is an open question on how we want to handle removing a named element: ln = list(a = 1, b = 2)
ln$a = NULL
ln
#> $b
#> [1] 2One way to support this operation would be to somehow allow to replace line 2 from above with |
|
Assigning One way to address this would be to implement a version of l <- list(a = 1, b = 2, c = 3)
l[not("b")]where not <- function(not_names) {
function(x) x[!names(x) %in% names(not_names)]
}Then `[.list` <- function(x, subset) {
UseMethod("[.list", subset)
}
`[.list.function` <- function(x, subset) {
subset(x)
}I generally like this style, where things that are generic over higher-order functions are used to provide functionality as opposed to bespoke syntax. They open up a lot of opportunities for more composable and expressive selectors. So maybe just to tie it back to this work, I think it's important to first and foremost implement what is most reasonable to the underlying data representation in the internals. It's the role of the standard library or other packages to add convenience syntax. |
|
superseded by: #180 |
TODOs:
.len()