Created
July 23, 2010 14:52
-
-
Save ajhager/487536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vec2: class { | |
x, y: Float | |
init: func (=x, =y) | |
repr: func -> String { "Vec2(%.2f, %.2f)" format(x, y) } | |
} | |
operator * (left: Float, right: Vec2) -> Vec2 { | |
return Vec2 new(left * right x, left * right y) | |
} | |
main: func { | |
v1 := Vec2 new(1.0, 1.0) | |
v2 := 2.0 * v1 | |
// Fails: test.c:91: error: incompatible types when initializing type | |
// 'lang_Numbers__Float' using type 'struct test__Vec2 *' | |
// Note: v2 is is being inferred as a Float and assigned a Vec2. | |
v3: Vec2 = 2.0 * v1 | |
v3 repr() println() | |
// Works: Vec2(2.0, 2.0) | |
v4 := (2.0 * v1) as Vec2 | |
v4 repr() println() | |
// Works: Vec2(2.0, 2.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment