tact icon indicating copy to clipboard operation
tact copied to clipboard

Simple destructuring of fields of structs and messages

Open novusnota opened this issue 1 year ago • 0 comments

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 avatar Apr 25 '24 16:04 novusnota