Hey all, I've been looking for a good first issue and it seems like the anonymous record update syntax issue would be a useful addition that's easy to model after the anonymous field accessor code. It's suggested to check here to make sure the issue is still relevant, which I expect is true based on the utility. Also, just to check, record updates are not valid for tuple "records", just standard records, right?
Meaning we only want to allow users to write:
&foo
-- updates to
\record, val ->
{ record & foo: val }
and not:
&0
-- updates to
\record, val ->
{ record & 0: val }
yep, that's correct - awesome! :smiley:
Looking forward to finally committing to a language I want to use. I have good confidence that Roc will succeed being backed by NoRedInk and friends, especially after watching "Why Isn't Functional Programming the Norm?"
(by backed, I don't mean sponsored)
@Gabriel Dertoni here's the thread where I started looking into the issue.
Hey, I would be interested in collaborating on this. I think I am pretty close to having an initial version working. However, I am a bit stuck trying to figure out how the type inference code works.
For the most part I just duplicates the field accessor code and changed things where necessary. Later today I can push to my fork of roc so you can have a look.
Sounds like we're in a similar boat.
I'll also push my code later. Hey, what are you thinking should be the name for the anonymous record updater syntax? Since the record access syntax is called both RecordAccessor
and RecordAccessorFunction
, I think a literal RecordUpdaterFunction
is the most readable name. I wish there was something terser that was as clear, but I don't see anything in the thesaurus.
Yep, I used something like this. Since the variants for record access and accessor were named respectivelly RecordAccess
and RecordAcessor
and there is already a RecordUpdate
, I named the new variant RecordUpdater
. and UpdaterFunction
in the AST.
I have managed to finish an initial implementation and have opened a pull request https://github.com/roc-lang/roc/pull/5367. If you have any feedback or differences from your implementation you would like to discuss, let me know.
In order to make this syntax even better, I think we should support nesting, like &foo.bar.baz
.
Left some comments on the PR, looks good! I've got some test_syntax
tests I can add. I'll start by putting them in my branch and you can consider pulling them into your PR.
Sounds good, will be looking into those comments soon.
Last updated: Jul 06 2025 at 12:14 UTC