Stream: beginners

Topic: Tutorial: self-referential record destructuring


view this post on Zulip Ian McLerran (Dec 31 2023 at 21:02):

I'm currently walking through the tutorial, and reached the point where the tutorial describes destructured record, in which an optional field is assigned a default expression which references another field in the destructured record.

These default values can reference other expressions in the record destructure; if you wanted, you could write
{ height, width, title ? "", description ? Str.concat "A table called " title }

Thus we have a destructured record in which the default value for the optional description field references the value of the title field of the same record.

To test this out, I wrote a short program to use this record, but get an error message on run, which tells me that The #UserApp module does not expose anything by the name title.

My code is the following:

app "records"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.1/Icc3xJoIixF3hCcfXrDwLCu4wQHtNdPyoJkEbkgIElA.tar.br" }
    imports [pf.Stdout]
    provides [main] to pf

main =
    Stdout.line (tableDesc { height: 10, width: 20 })

tableDesc =\{
        height,
        width,
        title ? "My Table",
        description ? Str.concat "A table called " title
    } -> Str.concat description " with dimensions \(Num.toStr width) x \(Num.toStr height)"

Am I missing something here? It would appear that the self-referential destructuring functionality is currently broken.

view this post on Zulip Brendan Hansknecht (Dec 31 2023 at 21:12):

Interesting. My gut feeling is it never worked (at least I don't recall ever seeing it working). Maybe the tutorial is ahead of the actual implementation there.

view this post on Zulip Ian McLerran (Dec 31 2023 at 21:17):

Thanks! If its true that the tutorial is ahead of the implementation, I'm curious what the workflow is for building the tutorial...

view this post on Zulip Brendan Hansknecht (Dec 31 2023 at 22:20):

I think the tutorial is all manually written currently without any compilation verification, but that could have changed since I last looked at that. Not really familiar with the code.

view this post on Zulip Elias Mulhall (Jan 01 2024 at 01:25):

I'm on my phone right now, but I dug into this a while ago and made a few GitHub issues

view this post on Zulip Anton (Jan 01 2024 at 09:57):

I've created some issues to test tutorial snippets on CI #6328 #6329.
#6328 is a good first issue :)

view this post on Zulip Ian McLerran (Jan 02 2024 at 02:33):

Anton said:

#6328 is a good first issue :)

Thanks! I forked the repo and gonna give it a shot

view this post on Zulip Michael Pfeifer (Jan 14 2024 at 20:32):

@Ian McLerran , I was looking for a first issue and took the first one that was unassigned: #6328. I started working on it and I only noticed that you are also working on it when I tried to find the origin of the issue. If you are still working on the issue, please let me know. Otherwise, I will open a pull request.

view this post on Zulip Ian McLerran (Jan 15 2024 at 23:33):

Michael Pfeifer go ahead, I'm finding that I have a lot to learn on Rust before I can easily dive into any issue. Its all yours!

view this post on Zulip Michael Pfeifer (Jan 16 2024 at 18:49):

@Ian McLerran, thanks for your response. I'll see what I can do.

view this post on Zulip Notification Bot (Jan 21 2024 at 18:04):

4 messages were moved from this topic to #contributing > Roc formatter replaces ### by # ## by Brendan Hansknecht.


Last updated: Jul 05 2025 at 12:14 UTC