Sometimes it would be nice to make a method that takes self not as a pointer, but as a value. For example, BigInt in #482 has no methods, and instead there are functions like def bigadd(x: BigInt, y: BigInt) -> BigInt. I did it that way because foo.add(bar).add(baz) didn't work (needs a pointer to foo.add(bar)), but bigadd(bigadd(foo, bar), baz) does work.
Maybe I should do something like this:
class Foo:
x: int
y: int
# Method that takes self a pointer
def print1(self) -> None:
printf("%d %d\n", self->x, self->y)
# Same thing, different syntax
def print1(self: Foo*) -> None:
printf("%d %d\n", self->x, self->y)
# Method that takes self by value
def print1(self: Foo) -> None:
printf("%d %d\n", self.x, self.y)
This would also kinda fix #439. You could use . if you want, but it's usually not what you want and usually you do -> instead.
Sometimes it would be nice to make a method that takes
self
not as a pointer, but as a value. For example,BigInt
in #482 has no methods, and instead there are functions likedef bigadd(x: BigInt, y: BigInt) -> BigInt
. I did it that way becausefoo.add(bar).add(baz)
didn't work (needs a pointer tofoo.add(bar)
), butbigadd(bigadd(foo, bar), baz)
does work.Maybe I should do something like this:
This would also kinda fix #439. You could use
.
if you want, but it's usually not what you want and usually you do->
instead.