erg/examples/class.er
2022-09-02 14:40:01 +09:00

17 lines
444 B
Python

@Inheritable
Point2D = Class {x = Int; y = Int}
Point2D.
new x, y = Self::__new__ {x; y}
norm ref self = self::x**2 + self::y**2
Point3D = Inherit Point2D, Additional := {z = Int}
Point3D.
@Override
new x, y, z = Self::__new__ {x; y; z}
@Override
norm ref self = self::x**2 + self::y**2 + self::z**2
UnpackPoint2D = Class {x = Int; y = Int}, Impl := Unpack
p = UnpackPoint2D::{x = 1; y = 2}
UnpackPoint2D::{x; y} = p