You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.fnnorm(a) -> {iftypeof(a) == "vec4"{return std::norm(a)}elseiftypeof(a) == "number"{return std::abs(a)}elseiftypeof(a) == "array"{return std::len(a)}}fn main(){
println(|(1,0)|)// Prints `1`
println(|-1|)// Prints `1`
println(|[1,2,3]|)// Prints `3`}
The text was updated successfully, but these errors were encountered:
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:
The text was updated successfully, but these errors were encountered: