Skip to content

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

Merged
merged 3 commits into from
Nov 6, 2018
Merged

Implement __sub__/__rsub__. #188

merged 3 commits into from
Nov 6, 2018

Conversation

cthulahoops
Copy link
Collaborator

Example of how to call attrs that exist.

@@ -0,0 +1,21 @@
assert 5 - 3 == 2

class Complex():
Copy link
Contributor

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):
Copy link
Contributor

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(
Copy link
Contributor

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.

@windelbouwman windelbouwman merged commit 3c4aaa0 into master Nov 6, 2018
@windelbouwman windelbouwman deleted the sub branch February 10, 2019 12:59
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

Successfully merging this pull request may close these issues.

2 participants