class support #663

Closed
mictadlo opened this Issue Apr 3, 2012 · 1 comment

3 participants

@mictadlo

Hello,
any plans to support class like in DART:
class Point {
Point(this.x, this.y);
distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return Math.sqrt(dx * dx + dy * dy);
}
var x, y;
}

main() {
Point p = new Point(2, 3);
Point q = new Point(3, 4);
print('distance from p to q = ${p.distanceTo(q)}');
}

@pao
The Julia Language member
pao commented Apr 3, 2012

I doubt it. Think of multiple dispatch as giving you an open class for every type.

type Point{T}
    x::T
    y::T
end

distanceTo(a::Point, b::Point) = sqrt((a.x-b.x)^2 + (a.y-b.y)^2)

println("distance from p to q = $(distanceTo(Point(2, 3), Point(3, 4)))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment