Stream: ideas

Topic: setter syntax


view this post on Zulip Richard Feldman (Feb 06 2022 at 19:06):

@Ayaz Hafiz suggested in another thread that we have a parallel of the .foo "field getter" syntax in a "field setter" syntax - so basically:

thoughts on those ideas?

view this post on Zulip Richard Feldman (Feb 06 2022 at 19:09):

could also do something like:

view this post on Zulip Martin Stewart (Feb 06 2022 at 19:39):

I do like that something like &name: blah is shorter but I don't like how it means there's two ways to do record updates.

Can multiple &name: blah be chained together? Something like this

record
    |> &name: blah
    |> &age: 6
    |> &bar: "foo"

If yes, maybe the { record & name: blah } syntax could be dropped and then there would be single concise way to do record updates.

That said, maybe this format makes it harder to give good error messages?

Edit: I guess in the case of updating many fields, the chained syntax is more verbose. So that's another downside.

view this post on Zulip Johannes Maas (Feb 06 2022 at 23:29):

I'm curious what examples are of where you would benefit from that sugar? (Can't find the original mention of this idea.)

view this post on Zulip Richard Feldman (Feb 07 2022 at 01:54):

idea #3 would make a big difference in a draft API I'm working through, so I'm curious what people think of the idea in general :big_smile:

view this post on Zulip jan kili (Feb 07 2022 at 01:57):

Richard Feldman said:

idea #3 would make a big difference in a draft API I'm working through, so I'm curious what people think of the idea in general :big_smile:

Oh, like it would simplify the code? I agree with @Johannes Maas, I'd love to see an example of cleaner code via setter sugar.

view this post on Zulip Richard Feldman (Feb 07 2022 at 02:02):

I'll share the API design when it's more fully baked (still working through it), but in the meantime, curious to hear opinions about use cases others have in mind!

view this post on Zulip Lucas Rosa (Feb 07 2022 at 20:30):

hm I like the user experience of idea 1 and 2 syntax wise but I'm not sure I have a strong opinion on what it should desugar to

view this post on Zulip Lucas Rosa (Feb 07 2022 at 20:30):

would be cool to be able to do 1 and 2 depending on the situation


Last updated: Jun 16 2026 at 16:19 UTC