I havenât read every proposal here (there are alot) but I donât see this one so I thought I would throw it out there.
To me (and a lot of other people) the biggest benefit of named arguments is default arguments. It would be great if this could be easily accomplishd in a struct. âBut that would require you to import the structâ⌠maybe not.
What if you could write annonymous structs like so:
fn foo(a: u8, b: u8, defaults: {
bar: u8,
baz: u8,
bam: u64,
zing: f64,
}) {
// do foo
}
and then the user could call it with
foo(1, 2, {bar: 10, bam: 12, ...}) // `...` means "rest are default"
// OR
foo(1, 2, {...}) // use only defaults
This way you never have to actually define the âdefaultsâ struct â it is defined implicitly. Also note you could use a defined struct for defaults and the user could call it the same way (without needing to import it).
This is also a way of implementing ânamed-onlyâ arguments, which I prefer for the cases where you want default arguments.
Edit1: this would have the advantage (or disadvantage) of allowing you to define and initialize struts without naming them â which may be good or bad. It could get you a python âdict-likeâ experience that is still type-checked.
Edit2: I would think this approach would use rustâs type inference ability, which allows you to say let x = foo() where foo() returns type Foo without needing to import type Foo.
Edit3: to have truly default arguments, we would have to resolve how to have default args for structs â but that is a giant todo anyway, and could use simple syntax.