Stream: beginners

Topic: anonymous record updates


view this post on Zulip Sam Mohr (May 02 2023 at 05:49):

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?

view this post on Zulip Sam Mohr (May 02 2023 at 05:52):

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 }

view this post on Zulip Richard Feldman (May 02 2023 at 05:53):

yep, that's correct - awesome! :smiley:

view this post on Zulip Sam Mohr (May 02 2023 at 05:56):

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?"

view this post on Zulip Sam Mohr (May 02 2023 at 06:01):

(by backed, I don't mean sponsored)

view this post on Zulip Sam Mohr (May 02 2023 at 17:33):

@Gabriel Dertoni here's the thread where I started looking into the issue.

view this post on Zulip Gabriel Dertoni (May 02 2023 at 17:38):

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.

view this post on Zulip Gabriel Dertoni (May 02 2023 at 17:41):

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.

view this post on Zulip Sam Mohr (May 02 2023 at 17:44):

Sounds like we're in a similar boat.

view this post on Zulip Sam Mohr (May 02 2023 at 17:47):

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.

view this post on Zulip Gabriel Dertoni (May 02 2023 at 19:39):

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.

view this post on Zulip Gabriel Dertoni (May 03 2023 at 06:39):

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.

view this post on Zulip Gabriel Dertoni (May 03 2023 at 06:43):

In order to make this syntax even better, I think we should support nesting, like &foo.bar.baz.

view this post on Zulip Sam Mohr (May 03 2023 at 16:33):

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.

view this post on Zulip Gabriel Dertoni (May 03 2023 at 17:31):

Sounds good, will be looking into those comments soon.


Last updated: Jul 06 2025 at 12:14 UTC