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

Allow use of multiple return value calls inside of expression #330

Closed
marekmaskarinec opened this issue Dec 25, 2023 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@marekmaskarinec
Copy link
Contributor

If one wants to use one of the results of a function inside of an expression, this can't be done in-place. The user must do something like this:

a, b := myFn()
c := a + 12

I'm proposing two solutions. The first one would add support for indexing the call like a struct. A question is whether we allow the user to save the result into a variable (I'm against it).

c := myFn().item1 + 12

The second would require changes to the := operator and the addition of _. The idea is that the value of the := operator is:

  • in case of 1 value - that value
  • in case of multiple values - a compile error
  • in case of multiple values, but only one is not a _ - that one value

Then this syntax would be possible:

c := (a, _ := myFn()) + 12
@vtereshkov vtereshkov added the enhancement New feature or request label Dec 25, 2023
@vtereshkov
Copy link
Owner

@marekmaskarinec

Proposal 1 is very close to how the multiple return values are stored under the hood. In fact, it is so close that even now you can do this trick by exploiting an innocent bug in Umka:

c := myFn().__field0 + 12

Proposal 2 looks cumbersome, to the point that at first I failed to read your example. At least, it requires the := operator to be an expression rather than a statement. It also implies a very special treatment of the _ placeholder in this context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants