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

builtin: cannot call print with multiple return values #7640

Closed
rui314 opened this issue Mar 26, 2014 · 6 comments
Closed

builtin: cannot call print with multiple return values #7640

rui314 opened this issue Mar 26, 2014 · 6 comments

Comments

@rui314
Copy link
Member

@rui314 rui314 commented Mar 26, 2014

What does 'go version' print?
go version devel +0a3722aa9092 Mon Mar 24 21:22:16 2014 -0400 linux/amd64

What steps reproduce the problem?
http://play.golang.org/p/UooyhhaOXQ

What happened?
Although print takes zero or more parameters, it cannot be called in the form of
print(f()), where f is a function returning two or more values. It looks inconsistent
and is sometimes a bit inconvenient.
@robpike
Copy link
Contributor

@robpike robpike commented Mar 26, 2014

Comment 1:

Not worth fixing. The print and println builtins are only for debugging, not convenience.

Status changed to WontFix.

@i3d
Copy link
Contributor

@i3d i3d commented Mar 26, 2014

Comment 2:

This is not just the builtin print or println. For example, fmt.Println or fmt.Printf
have the same issue. It seems that for any function signature with foo(a ...T), it will
accept parameters from a function with multi-value returns, but for any other forms
(e.g. foo(b string, a ...T)), it does not. The compiler will consider the return is in a
single-value context. This looks like a language limitation though, not really a bug per
se.
On the flip side, if we were planning to fix it, I'd suggest we could support a syntax
something like this: foo(a, f()...) where f()... denotes to assign multi-value returns
to the []T slice.

@cznic
Copy link
Contributor

@cznic cznic commented Mar 26, 2014

Comment 3:

@2: No, it works just fine: http://play.golang.org/p/ZZgIoN2FTw

@rui314
Copy link
Member Author

@rui314 rui314 commented Mar 26, 2014

Comment 4:

@2 and @3: Please refer the paragraph starting with "As a special case" in the language
spec (http://golang.org/ref/spec#Calls) for normal function calls. fmt.Println is
working as what the spec says.

@i3d
Copy link
Contributor

@i3d i3d commented Mar 27, 2014

Comment 5:

Ah.. Thanks Rob! That makes everything clear now.

@rui314
Copy link
Member Author

@rui314 rui314 commented Mar 27, 2014

Comment 6:

My username starts with "r" but I'm not Rob Pike. :)

@rui314 rui314 added the wontfix label Mar 27, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants