Named Arguments are Just Structs: Anonymous Struct Parameters

It's a great article, and I really feel the struggle of trying to reduce the syntax required for named arguments to work. On the other hand, it creates more problems and new language rules, especially special cases around the range literal syntax.

This makes it really hard to get any agreement on. Personally, I would be happy with inferred struct literal type _ { .. } syntax combined with the default field values. I.e. no anonymous struct, no extra sugar. We still have to name and declare structs for every function we need. Yes, we don't get the super succinct syntax in the world, but... That's already a huge win and an easier push as an intuitive extension to the language.

I want to add that having a named struct is usually a benefit. A plain composable struct, which you can pass around. I think often people miss the problem of wrapper functions. If you wrap a function with tons of parameters, you'd really want to avoid repeating them, and a named struct gives you that.

I generated a nice little dependency/relation graph to help people see how the proposed features and existing work stack up. It makes it more clear that feature(struct_pattern_inference) and feature(parameter_type_elision) are both possible by themselves.

That said, we could also do feature(anonymous_struct_parameters) and feature(anonymous_struct_pattern_elision) without having to address the real difficulties of feature(named_arguments) sugar, and I think it would make creating functions in many cases much nicer.

feature(parameter_type_elision) would likely be it's own independent RFC. I just chose to include it here since it's the spiritual sibling of feature(anonymous_struct_pattern_elision).

1 Like

FYI the diagram isn't legible in dark mode.

Really?

This is what it looks like for me on my website in Safari:

I see this in mobile Safari:

I believe it’s because I set the OS to light mode, but this website to dark mode, and I guess the font color is some OS-specific default not overridden by Discourse’s dark mode, for whatever reason.

2 Likes

Ah, it's an issue with using <img> for SVGs, since they don't get the stylesheets. I've updated the image in this thread to use a white background image. Sorry about that.

(My website still works in dark background :wink:)