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

Named argument syntax #26

Closed
bvssvni opened this issue Feb 3, 2016 · 0 comments
Closed

Named argument syntax #26

bvssvni opened this issue Feb 3, 2016 · 0 comments
Assignees

Comments

@bvssvni
Copy link
Member

bvssvni commented Feb 3, 2016

Example:

fn say__msg_to(msg, person) {
    print(person + "! ")
    println(msg)
}

fn main() {
    // Normal call syntax.
    say__msg_to("hi!", "you there")
    // Named argument call syntax.
    say(msg: "hi!", to: "you there")
}

Two underscores __ separates arguments from the function name. A single underscore _ separates arguments.

This syntax has the following benefits:

  • No extra information required - maps to same function
  • Can change the name of arguments without causing breaking changes
  • Fits with the Rust's snake_case for function names
  • Arguments are ordered, making it faster to parse than unordered arguments
  • Can use long function names for many arguments
  • Easy to refactor into objects
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