mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
13 lines
333 B
Python
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
|