Hacker News new | ask | show | jobs
by Rotareti 2957 days ago
Not essential but keyword arguments / named parameters / default arguments. I love those in Python and OCaml/ReasonML.
1 comments

You can make functions with default arguments right now (a little easier thanks to Impl Trait):

http://play.rust-lang.org/?gist=4f74d3dcee0031e99cb99bb54da5...

Concerning keyword args as I remember them from Python you would probably have to hack something together with an Into<Option<HashMap<some_type_for_arg_names, some_enum_with_variants_containing_acceptable_types>>>

Concerning "named paramters" I think you would have to apply some of the same trickery in order to be able when calling the fn to leave out args or give them in a different order than specified in the fn header.

Or what I've sometimes seen written was (e.g. for configuration passing) structs created with Option<some_type> that were then passed to one or more functions which in turn get the values (named params/default args if you will) from that "object", being able to pick and choose the appropriate values to get in a given function/method.