Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple destructuring of fields of structs and messages #298

Closed
novusnota opened this issue Apr 25, 2024 · 0 comments · Fixed by #856
Closed

Simple destructuring of fields of structs and messages #298

novusnota opened this issue Apr 25, 2024 · 0 comments · Fixed by #856
Assignees
Milestone

Comments

@novusnota
Copy link
Member

novusnota commented Apr 25, 2024

Instead of:

message SomeMsg {
    iField: Int;
    sField: String;
}

receive(msg: SomeMsg) {
    let first: Int = msg.iField;
    let second: Int = msg.sField;
}

we could have the following:

message SomeMsg {
    iField: Int;
    sField: String;
}

receive(msg: SomeMsg) {
    let { first, second } = msg; // when we'll have a local type inference from #161
    // and
    let { onlyFirst, _ } = msg; // discarding the unwanted fields
    
    // Trailing commas should be allowed as well:
    let { firstAgain, secondAgain, } = msg;
    
    // The inverse of such destructuring operation is already present in the language:
    SomeMsg{ iField: first, sField: second };
}

Note, that this won't require any advanced pattern matching capabilities and should be rather simple to implement in the compiler. Marked this as a discussion because this is just a suggestion. This may or may not drive further improvements of working with Structs and Messages to make it much more convenient.

Depends on #161.

@novusnota novusnota added enhancement New feature or request discussion Ideas that are not fully formed and require discussion language design labels Apr 25, 2024
@novusnota novusnota changed the title Simple destructuring for structs and messages Simple destructuring of fields of structs and messages Apr 25, 2024
@anton-trunov anton-trunov added this to the v1.4.0 milestone Apr 26, 2024
@anton-trunov anton-trunov added language feature and removed language design enhancement New feature or request discussion Ideas that are not fully formed and require discussion labels Apr 26, 2024
@anton-trunov anton-trunov modified the milestones: v1.4.0, v1.5.0 Jun 12, 2024
@anton-trunov anton-trunov modified the milestones: v1.5.0, v1.6.0 Jul 30, 2024
@Gusarich Gusarich self-assigned this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants