racket/collects/honu/examples/point.honu
Stevie Strickland 7dbb99d3c6 merged 292:296 from branches/sstrickl
svn: r297
2005-07-02 04:03:02 +00:00

37 lines
1.1 KiB
Plaintext

struct PointC(int x, int y) : Point { }
struct ColorC(int r, int g, int b) : Color { }
// Make extends clause look more like the first part of a class/struct,
// where the "with" args come in the same place as the init slots normally.
struct Point3DC(int z) : Point3D extends PointC() : Point { super(); }
type ColorPoint <: Point { Color c; }
type MovingPoint <: Point { void movePoint(int, int); }
// Make mixins look more like functions for classes to classes by
// making their "type" look more like the following:
//
// <input class type>(<with args>) -> <output class type>
mixin addColor(Color c) : Point() -> ColorPoint impl ColorPoint {
super();
export ColorPoint : x, y, c;
}
mixin makeMobile() : Point() -> MovingPoint impl MovingPoint {
super();
void movePoint(int dx, int dy) {
x = x + dx;
y = y + dy;
}
export MovingPoint : x, y, movePoint;
}
class ColorPointC = addColor(PointC);
class MovingPointC = makeMobile(PointC);
// only useable as a MovingPoint
class MovingColorPointC = makeMobile(ColorPointC);
// only usable as a ColorPoint
class ColorMovingPointC = addColor(MovingPointC);