erg/examples/add.er
Shunsuke Shibayama fe552e23b1 Fix parser bugs
2022-09-08 00:55:25 +09:00

13 lines
333 B
Python

Point = Class {x = Int; y = Int}, Impl := Add() and Eq()
Point.
new x, y = Self::__new__ {x; y}
norm self = self::x**2 + self::y**2
@Impl Add()
`+` self, other =
Self.new(self::x + other::x, 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