Make namespace `std` for standard external functions
bvssvni opened this issue · comments
By making binary and unary operators external functions (see #635), it becomes possible to override operators by declaring a function with same name. In order to preserve existing functionality while extending with new functionality, there must be a way to call the standard operators.
For example:
use std as std
// Override the `|<expr>|` operator.
fn norm(a) -> {
if typeof(a) == "vec4" {
return std::norm(a)
} else if typeof(a) == "number" {
return std::abs(a)
} else if typeof(a) == "array" {
return std::len(a)
}
}
fn main() {
println(|(1, 0)|) // Prints `1`
println(|-1|) // Prints `1`
println(|[1, 2, 3]|) // Prints `3`
}