Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make namespace std for standard external functions #639

Closed
bvssvni opened this issue Sep 17, 2019 · 0 comments
Closed

Make namespace std for standard external functions #639

bvssvni opened this issue Sep 17, 2019 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Sep 17, 2019

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`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant