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: )
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.
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:
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.
Steven Chen has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC