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

fmt: mismatch between explicit argument index documentation and behaviour #9632

Closed
kortschak opened this issue Jan 19, 2015 · 6 comments
Closed

Comments

@kortschak
Copy link
Contributor

The documentation describing explicit argument indexes in format strings does not state that if an argument is refered to by an explicit argument index in the first place that following verbs must also have an explicit index.

Currently this gives surprising results:

package main

import "fmt"

func main() {
    fmt.Printf("%[2]d is the %[1]s\n", "answer", 42)
    fmt.Printf("%d is the %[2]s\n", 42, "answer")
    fmt.Printf("%[2]d is the %s\n", "answer", 42)
}
42 is the answer
42 is the answer
42 is the %!s(MISSING)

http://play.golang.org/p/HP11QHqa_p

@minux
Copy link
Member

minux commented Jan 19, 2015

“After processing a bracketed expression [n], arguments n+1, n+2, etc. will be processed unless otherwise directed.”

Working as intended.

@minux minux closed this as completed Jan 19, 2015
@kortschak
Copy link
Contributor Author

The wording is less than entirely clear.

@minux
Copy link
Member

minux commented Jan 19, 2015

Then we have:

Because an explicit index affects subsequent verbs, this notation can be
used to print the same values multiple times by resetting the index for the
first argument to be repeated:

fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
will yield "16 17 0x10 0x11".

It states very clear that explicit index affects the following verbs, and
then you should
be able to understand the preceding statement:
"After processing a bracketed expression [n], arguments n+1, n+2, etc. will
be processed unless otherwise directed."

What confuses you?

@kortschak
Copy link
Contributor Author

What left me confused was that that final sentence does not explicitly mention that the argument cursor will be used as in the updated state (or words to that effect). I think a single clause between "processed" and "unless" making this clear would improve the explanation.

@minux
Copy link
Member

minux commented Jan 19, 2015

OK. Perhaps processing is confusing here. How about changing:
"After processing a bracketed expression [n], arguments n+1, n+2, etc. will be processed unless otherwise directed."
to:
"After processing a bracketed expression [n], subsequent verbs will use arguments n+1, n+2, etc. unless otherwise directed."

@minux minux reopened this Jan 19, 2015
@kortschak
Copy link
Contributor Author

SGTM

@minux minux closed this as completed in e12b1dd Jan 19, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants