You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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:
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).
The second would require changes to the
:=
operator and the addition of_
. The idea is that the value of the:=
operator is:_
- that one valueThen this syntax would be possible:
The text was updated successfully, but these errors were encountered: