PistonDevelopers / dyon

A rusty dynamically typed scripting language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Named argument syntax

bvssvni opened this issue · comments

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