Stream: beginners

Topic: ✔ Record update syntax


view this post on Zulip Steven Chen (Dec 19 2023 at 23:28):

I really like the record update capability but am also curious the syntax design. Let's use this example:

a = {x: 1, y: 2}
b = {a & x: 3, y: 4}

1) a is a record but it is inside the curly brackets (feels/reads like a is field in b).
2) the strange feeling on the precedence of & operator. Everything following & is the update. But due to the comma, we might also read as: update x in a to 3 and set as value for field a, add another field y to b which is 4.

IMHO, the update syntax would look better with b = a & {x: 3, y: 4} to avoid those two confusions (maybe just me :smile: )

view this post on Zulip Ryan Bates (Dec 20 2023 at 00:16):

I agree the record update syntax isn't intuitive and has tripped me up a few times. It still feels out of place to me after working with Roc for a few weeks.

It sounds like a & b will be difficult to implement as discussed in this thread. However I think it deserves more discussion.

view this post on Zulip Richard Feldman (Dec 20 2023 at 00:25):

we could make & have to always be followed by { to fix that problem, but I feel like that would be confusing to beginners in different ways :sweat_smile:

view this post on Zulip Steven Chen (Dec 20 2023 at 00:32):

Richard Feldman said:

we could make & have to always be followed by { to fix that problem, but I feel like that would be confusing to beginners in different ways :sweat_smile:

that seems worse :sweat_smile: . i will resolve this thread given the existing thread in ideas channel covered everything i wrote here.

view this post on Zulip Notification Bot (Dec 20 2023 at 00:32):

Steven Chen has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC