1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:04:40 -07:00
go/doc
Rob Pike 7472ce0e58 fmt.Printf: introduce notation for random access to arguments.
This text is added to doc.go:

        Explicit argument indexes:

        In Printf, Sprintf, and Fprintf, the default behavior is for each
        formatting verb to format successive arguments passed in the call.
        However, the notation [n] immediately before the verb indicates that the
        nth one-indexed argument is to be formatted instead. The same notation
        before a '*' for a width or precision selects the argument index holding
        the value. After processing a bracketed expression [n], arguments n+1,
        n+2, etc. will be processed unless otherwise directed.

        For example,
                fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
        will yield "22, 11", while
                fmt.Sprintf("%[3]*[2].*[1]f", 12.0, 2, 6),
        equivalent to
                fmt.Sprintf("%6.2f", 12.0),
        will yield " 12.00". 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".

The notation chosen differs from that in C, but I believe it's easier to read
and to remember (we're indexing the arguments), and compatibility with
C's printf was never a strong goal anyway.

While we're here, change the word "field" to "arg" or "argument" in the
code; it was being misused and was confusing.

R=rsc, bradfitz, rogpeppe, minux.ma, peter.armitage
CC=golang-dev
https://golang.org/cl/9680043
2013-05-24 15:49:26 -07:00
..
articles all: fix typos 2013-04-24 04:46:14 +08:00
codewalk all: fix typos 2013-04-24 04:46:14 +08:00
devel all: fix typos 2013-04-24 04:46:14 +08:00
gopher doc/gopher: add high-resolution pencil sketches 2012-12-12 10:51:13 -08:00
play doc/play: sync playground.js with go-playground repo 2012-12-13 14:32:03 +11:00
progs effective_go.html: move and rework the blank identifier section 2013-03-08 10:41:20 -08:00
cmd.html doc: move /ref/cmd to /doc/cmd 2012-03-27 13:46:16 +11:00
code.html doc/code.html: remove doubled word; modify the tab to space. 2013-04-23 13:13:51 -07:00
contrib.html doc: link to wiki Projects page instead of old Project Dashboard. 2013-02-11 09:18:31 +11:00
contribute.html doc/contribute: add instructions to fix codereview on windows 2013-03-11 12:14:42 +11:00
debugging_with_gdb.html doc: correct some minor HTML errors found by tidy 2013-02-28 13:32:36 -08:00
docs.html doc: link to Go 1.1 release notes 2013-05-01 10:00:05 -04:00
effective_go.html effective_go.html: be more accepting in the guidelines for interface names 2013-05-07 11:41:36 -07:00
gccgo_contribute.html doc: more doubled words 2013-04-16 14:20:06 -07:00
gccgo_install.html doc: general update of gccgo_install 2012-03-20 14:16:34 -07:00
go1.1.html doc: GCC 4.8.1 is not updated to Go 1.1 2013-05-22 13:05:31 -07:00
go1.2.txt fmt.Printf: introduce notation for random access to arguments. 2013-05-24 15:49:26 -07:00
go1.html doc: misc tweaks, new links, fix broken links 2013-04-18 12:43:23 -07:00
go1compat.html doc: add note about import . to Go 1 compatibility notes 2012-03-06 17:50:11 -08:00
go_faq.html doc/go_faq: fix example. 2013-05-22 12:28:58 +10:00
go_mem.html doc: Don't imply incorrect guarantees about data races. 2012-09-11 08:47:30 +10:00
go_spec.html spec: removed old or invalid TODOs 2013-05-20 14:01:07 -07:00
go-logo-black.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
go-logo-blue.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
go-logo-white.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
godocs.js godoc: enable visibility of element linked from URL hash 2013-04-05 08:04:02 +11:00
help.html doc: add mention of the Go+ community 2013-01-25 08:27:34 +11:00
ie.css golang.org redesign 2010-09-16 14:01:02 +10:00
install-source.html doc: move os specific build instructions to wiki 2013-02-10 17:39:13 -05:00
install.html doc: more doubled words 2013-04-16 14:20:06 -07:00
jquery.js godoc: add jQuery to Go repository, rewrite godocs.js to use jQuery 2012-10-04 15:31:25 +10:00
logo-153x55.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
Makefile doc/progs: use test/run.go for testing on Windows 2012-09-03 03:49:03 +08:00
reference.html doc: misc tweaks, new links, fix broken links 2013-04-18 12:43:23 -07:00
root.html doc: pull front page featured articles using new blog JSON feed 2013-05-08 09:23:50 -07:00
share.png godoc: change link styles, add 'pop out' button 2012-03-13 11:00:11 +11:00
sieve.gif repair corrupted sieve.gif 2009-10-30 10:34:01 -07:00
style.css doc: add prominent download button to getting started page 2013-04-03 15:59:17 +11:00
tos.html doc: add Terms of Service 2012-03-27 09:27:43 +11:00