-
Notifications
You must be signed in to change notification settings - Fork 2
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
Multi return functions as expressions. #88
Comments
i don't think that we should do return value unpacking: func foo(int x, int y) int, int{ return x, y; }
func boo(int x, int y) int, int{ return x, y; }
bool(foo(1,2)) Though it would be possible to do so, i just don't think it's worth our time right now. I do think that we should allow functions to be used as expressions: x = y + foo(1, 1) This is pretty standard usage of functions to compose expressions. agreed that calling a function w/o values to be assigned is fine. |
So functions can be used in expressions but if it returns multiple values or void I don't think it should be allowed. Like int the above if foo returned 2 ints, it would fail but if foo returned just an int or string or whatever type x and y were it would compile. Is that fine? |
oops, i misread your example and assumed agreed on all points. |
fwiw, i think we could get away with implementing the unpacking in function arguments since we can just call |
Does go support this in any way? because even if we could translate and check it might make code generation hard. I'm going to skip for now and if we have time I'll revisit |
// go supports this:
func foo(a, b int) (int, int) { return foo(a, b)}
// but not this
func bar(a, b, c int) (int, int) { return foo(a, b)}
bar(1, foo(1,2)) but we can make them both work generated code: // go supports this:
func foo(a, b int) (int, int) {
x, y = foo(a,b)
return x, y
}
func bar(a, b, c int) (int, int) {
x, y = foo(a,b)
return x, y
}
// bar(1, foo(1,2))
a, b = foo(1, 2)
bar(1, b, c) |
So I have small issue with calling functions. If a function returns multiple values in general It will not be allowed in an expression because we have no notion of tuples.
However a function call to a func returning 2 values could be used as 2 args or as 2 return values.
I think this needs to work with returns so we can do some easier recursion.
func boo(int x, int y) int, int{ return boo(x+1, y-1); }
I know this is infinite but syntactically makes sense to do compared to:
func boo(int x, int y) int, int{ (x, y) = boo(x+1 y-1); return x, y; }
The text was updated successfully, but these errors were encountered: