-
Notifications
You must be signed in to change notification settings - Fork 4
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
Document classes #598
Document classes #598
Conversation
doc/classes.md
Outdated
If, for some reason, you want to pass the instance by value instead of a pointer, | ||
you can specify the type of `self` like this: | ||
|
||
```python | ||
import "stdlib/io.jou" | ||
|
||
class Point: | ||
x: int | ||
y: int | ||
|
||
def increment_y(self: Point) -> None: # pass self by value | ||
self.y++ | ||
printf("incremented to %d\n", self.y) | ||
|
||
def main() -> int: | ||
p = Point{x=12, y=34} | ||
p.increment_y() # Output: incremented to 35 | ||
printf("still %d\n", p.y) # Output: still 34 | ||
return 0 | ||
``` |
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.
Feel a little bit confusing when reading this part about the using of self
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.
Thanks for reviewing! Is it better now?
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.
Thanks for reviewing! Is it better now?
Better now, but I perfer Point
as default instead of Point*
XD
Fixes #517