-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement __sub__/__rsub__. #188
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
@@ -0,0 +1,21 @@ | |||
assert 5 - 3 == 2 | |||
|
|||
class Complex(): |
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.
Note complex
builtin type is also present, no issue here though.
def __repr__(self): | ||
return "Com" + str((self.real, self.imag)) | ||
|
||
def __sub__(self, other): |
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.
Good check! Here lies the proof of the pudding indeed!
vm/src/vm.rs
Outdated
} else if b.has_attr("__rsub__") { | ||
self.call_method(&b, "__rsub__", vec![a]) | ||
if let Ok(method) = self.get_method(a.clone(), "__sub__") { | ||
self.invoke( |
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.
Maybe we can add a invoke_with_args
method which is less vebose.
Example of how to call attrs that exist.