Source

vector3-io / vector3.io

Full commit
#!/usr/bin/env io
# Make a 3d-vector class
Vector3 := Object clone;
Vector3 make := method(x, y, z,
                       result := Vector3 clone;
                       result x := x;
                       result y := y;
                       result z := z;
                       result
                      )

# Add dot product function
Vector3  := method(other,
                    other x * x +  
                    other y * y +  
                    other z * z
                   )

# Add cross product function
Vector3  := method(other,
                    Vector3 make (
                            y * other z - z * other y,
                            z * other x - x * other z,
                            x * other y - y * other x
                           )
                   )

# Make the functions infix operators in the language
# (2 is the same precedence level as *, / and %)
OperatorTable addOperator("⋅", 2)
OperatorTable addOperator("⨯", 2)

# Test case needs to be in a different file, since tokenizing
# happened before ⋅ and ⨯ were operators.
doFile("test.io")