Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
Add Comment
Please, Sign In to add comment