erg/examples/impl.er
Shunsuke Shibayama 0040ea4b07 Add test
2022-10-14 16:06:00 +09:00

17 lines
464 B
Python

Point = Class {x = Int; y = Int}
Point.
new x, y = Point::__new__ {x; y}
norm self = self::x**2 + self::y**2
Point|Point <: Add(Point)|.
Output = Point
__add__ self, other: Point =
Point.new(self::x + other::x, self::y + other::y)
Point|Point <: Eq(Point)|.
__eq__ self, other: Point =
self::x == other::x and self::y == other::y
p = Point.new 1, 2
q = Point.new 3, 4
r = p + q
assert r == Point.new 4, 6
assert r.norm() == 52