-
Notifications
You must be signed in to change notification settings - Fork 38
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
Explore group generics implementation #365
base: main
Are you sure you want to change the base?
Conversation
To do:
|
#Conflicts: # NAMESPACE # R/method-ops.R # R/zzz.R
@t-kalinowski @DavisVaughan before I finish up the implementation for the other group generics, could you please take a look at how it works for Math? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice to me!
S7_error_method_not_found = function(cnd) NULL | ||
) | ||
|
||
NextMethod() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call NextMethod()
? Isn't S7_object
always the right-most class? It would be nice to throw the S7 method not found error if we could
@@ -16,17 +16,24 @@ on_load_define_ops <- function() { | |||
|
|||
#' @export | |||
Ops.S7_object <- function(e1, e2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this all live in method-group.R
now?
} | ||
|
||
#' @export | ||
Math.S7_object <- function(x, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you also need to check for a "specific" generic call here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a very nice solution. I see no issues.
Sorry if I'm a "game spoiler": Using |
If you can suggest an alternative implementation, I'm happy to try it. But I couldn't think of another way to do it. |
One approach might be to update S7_Math <<- new_generic("Math", "x", function(x, ..., .Generic) {
cl <- .Call(method_call_, sys.call(), sys.function(), sys.frame())
if(is.null(cl))
NextMethod()
else
eval(cl)
}) |
"Nice"! That would almost surely be an order of magnitude faster! Possibly we'd even want to provide (and document and use ourselves) a thin wrapper around |
Ok, I'll take a stab at that approach. |
Fixes #353