buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.15k stars 31 forks source link

Argument/Property name can be omitted if variable passed has same name #204

Closed giann closed 8 months ago

giann commented 9 months ago

buzz only allows the first argument of a function to be unnamed. I stand by that choice but sometimes, named argument can be a little repetitive if the value passed has the same name.

With this, we would go from:

fun hello(str firstname, str lastname, int age) > void {
    | ...
}

hello(firstname, lastname: lastname, age: calculatedAge);

to:

fun hello(str firstname, str lastname, int age) > void {
    | ...
}

hello(firstname, lastname, age: calculatedAge);

We can do the same for object initialization (like rust):

object Person {
    str firstname,
    str lastname,
    int age,
}

var person = Person{
    firstname,
    lastname,
    age = calculatedAge
}
matdexir commented 9 months ago

That's a good one! It really makes the language feel more natural.