| I haven't seen anything for or against in actual roadmaps. But there is, of course, at least one pre-proposal: https://internals.rust-lang.org/t/pre-rfc-named-arguments/16... It doesn't think about optional arguments (but somehow does include overloading). And a bit in a related fashion, it doesn't permit for reordering calling arguments, which I consider a downside: > Reordering named arguments when calling > No it is not possible. Just like unnamed arguments and generics, named arguments are also position-based and cannot be reordered when calling: register(name:surname:) cannot be called as register(surname:name:). > Reordering them at the definition site is an API break, just like reordering unnamed arguments or generics is an API break already. The rationale for this expressed in the comments says it's incompatible with overloading, but to me I don't see why named arguments and overloading should go hand-in-hand—or, indeed, how desirable overloading is in the first place. Or why should overloading be able to overload that kind of scenario. The other reasons for this don't seem really problems at all. > fn func2(pub name: u32, name hidden: u32) { /\* ... */ }
> fn func3(name hidden1: u32, name hidden2: u32) { /* ... */ }
> func2 and func3 could work in theory: named arguments as proposed in this RFC are position-based and their internal names are different: just like two arguments can have the same type without ambiguity, those functions could be allowed.Maybe there are technical reasons that are simpler when considering type compatibility between function types that have or don't have labeled arguments? Seems the proposal has misunderstood something about OCaml labeled arguments when placing it under https://internals.rust-lang.org/t/pre-rfc-named-arguments/16... , though. In addition the proposal doesn't seem to have a neat syntax for forwarding named parameters, like in constructing records you can just fill in a field called foo by mentioning its name by itself—or, like in OCaml you can have let foo ~bar = bar + 1
let baz ~bar = foo ~bar
let main () = baz ~bar:42
If it used the .-prefix as mentioned as an idea elsewhere, then this too could be naturally expressed.Maybe there are other ideas how to go about the labeled arguments, though that one seems pretty well thought-out. One thing I've enjoyed with Python (and Mypy) is the ability to require the caller to use named arguments with the asterisk marker in the parameter list. This idea is mentioned in the proposal. |