diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
commit | d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61 (patch) | |
tree | 1833f8b72a4b3a8f00d0d143b079a8fcad01c6ae /doc | |
parent | 8652e6c371b8905498d3d314491d36c58d5f68d5 (diff) | |
download | golang-d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61.tar.gz |
Imported Upstream version 58upstream/58
Diffstat (limited to 'doc')
-rw-r--r-- | doc/GoCourseDay1.pdf | bin | 904237 -> 287552 bytes | |||
-rw-r--r-- | doc/all.css | 7 | ||||
-rw-r--r-- | doc/codelab/wiki/get.go | 2 | ||||
-rw-r--r-- | doc/codelab/wiki/index.html | 2 | ||||
-rw-r--r-- | doc/codelab/wiki/wiki.html | 2 | ||||
-rw-r--r-- | doc/contrib.html | 11 | ||||
-rw-r--r-- | doc/contribute.html | 3 | ||||
-rw-r--r-- | doc/devel/release.html | 72 | ||||
-rw-r--r-- | doc/devel/roadmap.html | 4 | ||||
-rw-r--r-- | doc/devel/weekly.html | 341 | ||||
-rw-r--r-- | doc/docs.html | 30 | ||||
-rw-r--r-- | doc/effective_go.html | 56 | ||||
-rw-r--r-- | doc/frontpage.css | 3 | ||||
-rw-r--r-- | doc/go_faq.html | 88 | ||||
-rw-r--r-- | doc/go_mem.html | 20 | ||||
-rw-r--r-- | doc/go_spec.html | 306 | ||||
-rw-r--r-- | doc/go_tutorial.html | 86 | ||||
-rw-r--r-- | doc/go_tutorial.txt | 32 | ||||
-rw-r--r-- | doc/godocs.js | 6 | ||||
-rw-r--r-- | doc/htmlgen.go | 4 | ||||
-rw-r--r-- | doc/root.html | 5 | ||||
-rw-r--r-- | doc/talks/io2011/Real_World_Go.pdf | bin | 0 -> 609477 bytes | |||
-rw-r--r-- | doc/talks/io2011/Writing_Web_Apps_in_Go.pdf | bin | 0 -> 729499 bytes | |||
-rw-r--r-- | doc/video-005.jpg | bin | 0 -> 6783 bytes |
24 files changed, 827 insertions, 253 deletions
diff --git a/doc/GoCourseDay1.pdf b/doc/GoCourseDay1.pdf Binary files differindex c2c8c4a7d..5a7749c18 100644 --- a/doc/GoCourseDay1.pdf +++ b/doc/GoCourseDay1.pdf diff --git a/doc/all.css b/doc/all.css index e496388ef..a985d8ffb 100644 --- a/doc/all.css +++ b/doc/all.css @@ -140,7 +140,7 @@ h1#title { } #content h2 { border-top: 2px solid #ddd; - padding: 8px 5px; + padding: 8px 0; margin: 1.5em 0 0; } #content .subtitle { @@ -198,3 +198,8 @@ span.alert { padding: 0.25em 1em; background: #F4F4F4; } +sup.new { + color: red; + font-size: 8px; + line-height: 0; +} diff --git a/doc/codelab/wiki/get.go b/doc/codelab/wiki/get.go index 342831416..c36684e3e 100644 --- a/doc/codelab/wiki/get.go +++ b/doc/codelab/wiki/get.go @@ -37,7 +37,7 @@ func main() { b := strings.NewReader(*post) r, err = http.Post(url, "application/x-www-form-urlencoded", b) } else { - r, _, err = http.Get(url) + r, err = http.Get(url) } if err != nil { log.Fatal(err) diff --git a/doc/codelab/wiki/index.html b/doc/codelab/wiki/index.html index d059fa027..cc187ad90 100644 --- a/doc/codelab/wiki/index.html +++ b/doc/codelab/wiki/index.html @@ -501,7 +501,7 @@ This will prevent user data from corrupting the form HTML. </p> <p> -Now that we've removed the <code>fmt.Sprintf</code> statement, we can remove +Now that we've removed the <code>fmt.Fprintf</code> statement, we can remove <code>"fmt"</code> from the <code>import</code> list. </p> diff --git a/doc/codelab/wiki/wiki.html b/doc/codelab/wiki/wiki.html index 3628eeb56..4db880b9d 100644 --- a/doc/codelab/wiki/wiki.html +++ b/doc/codelab/wiki/wiki.html @@ -428,7 +428,7 @@ This will prevent user data from corrupting the form HTML. </p> <p> -Now that we've removed the <code>fmt.Sprintf</code> statement, we can remove +Now that we've removed the <code>fmt.Fprintf</code> statement, we can remove <code>"fmt"</code> from the <code>import</code> list. </p> diff --git a/doc/contrib.html b/doc/contrib.html index 9d0c42726..84d2cda6a 100644 --- a/doc/contrib.html +++ b/doc/contrib.html @@ -4,7 +4,7 @@ <h2 id="howto">How you can help</h2> -<h3>Reporting issues</h3> +<h3><a href="http://code.google.com/p/go/issues">Reporting issues</a></h3> <p> If you spot bugs, mistakes, or inconsistencies in the Go project's code or @@ -19,7 +19,7 @@ a new one.) We pride ourselves on being meticulous; no issue is too small. </p> -<h3>Contributing code</h3> +<h3><a href="contribute.html">Contributing code</a></h3> <p> Go is an open source project and we welcome contributions from the community. @@ -39,7 +39,7 @@ are particularly in need of outside help. <div class="right-column"> -<h2 id="">The Go Project</h2> +<h2 id="the_go_project">The Go Project</h2> <h3 id="build_status"><a href="http://godashboard.appspot.com/">Build Status</a></h3> <p>View the status of Go builds across the supported operating @@ -49,7 +49,10 @@ systems and architectures.</p> <p>Features and ideas being developed or discussed by the Go team.</p> <h3 id="release"><a href="devel/release.html">Release History</a></h3> -<p>A summary of the changes between tagged releases of Go.</p> +<p>A summary of the changes between Go releases.</p> + +<h3 id="release"><a href="devel/weekly.html">Weekly Snapshot History</a></h3> +<p>A summary of the changes between weekly snapshots of Go.</p> <h3 id="golang-dev"><a href="http://groups.google.com/group/golang-dev">Developer Mailing List</a></h3> <p>The <a href="http://groups.google.com/group/golang-dev">golang-dev</a> diff --git a/doc/contribute.html b/doc/contribute.html index ba70c9600..c4b1ce2b5 100644 --- a/doc/contribute.html +++ b/doc/contribute.html @@ -209,7 +209,8 @@ The <code>Reviewer</code> line lists the reviewers assigned to this change, and the <code>CC</code> line lists people to notify about the change. These can be code review nicknames or arbitrary email addresses. -If you don't know who is best to review the change, set the +Unless explicitly told otherwise, such as in the discussion leading +up to sending in the change list, set the reviewer field to the <a href="http://groups.google.com/group/golang-dev">golang-dev@googlegroups.com</a> mailing list. diff --git a/doc/devel/release.html b/doc/devel/release.html index 84ca622fa..d632200d3 100644 --- a/doc/devel/release.html +++ b/doc/devel/release.html @@ -14,6 +14,78 @@ hg pull hg update release.r<i>NN</i> </pre> +<h2 id="r58">r58 (released 2011/06/29)</h2> + +<p> +The r58 release corresponds to +<code><a href="weekly.html#2011-06-09">weekly.2011-06-09</a></code> +with additional bug fixes. +This section highlights the most significant changes in this release. +For a more detailed summary, see the +<a href="weekly.html#2011-06-09">weekly release notes</a>. +For complete information, see the +<a href="http://code.google.com/p/go/source/list?r=release-branch.r58">Mercurial change list</a>. +</p> + +<h3 id="r58.lang">Language</h3> + +<p> +This release fixes a <a href="http://code.google.com/p/go/source/detail?r=b720749486e1">use of uninitialized memory in programs that misuse <code>goto</code></a>. +</p> + +<h3 id="r58.pkg">Packages</h3> + +<p> +As usual, <a href="/cmd/gofix/">gofix</a> will handle the bulk of the rewrites +necessary for these changes to package APIs. +</p> + +<p> +<a href="/pkg/http/">Package http</a> drops the <code>finalURL</code> return +value from the <a href="/pkg/http/#Client.Get">Client.Get</a> method. The value +is now available via the new <code>Request</code> field on <a +href="/pkg/http/#Response">http.Response</a>. +Most instances of the type map[string][]string in have been +replaced with the new <a href="/pkg/http/#Values">Values</a> type. +</p> + +<p> +<a href="/pkg/exec/">Package exec</a> has been redesigned with a more +convenient and succinct API. +</p> + +<p> +<a href="/pkg/strconv/">Package strconv</a>'s <a href="/pkg/strconv/#Quote">Quote</a> +function now escapes only those Unicode code points not classified as printable +by <a href="/pkg/unicode/#IsPrint">unicode.IsPrint</a>. +Previously Quote would escape all non-ASCII characters. +This also affects the <a href="/pkg/fmt/">fmt</a> package's <code>"%q"</code> +formatting directive. The previous quoting behavior is still available via +strconv's new <a href="/pkg/strconv/#QuoteToASCII">QuoteToASCII</a> function. +</p> + +<p> +<a href="/pkg/os/signal/">Package os/signal</a>'s +<a href="/pkg/os/#Signal">Signal</a> and +<a href="/pkg/os/#UnixSignal">UnixSignal</a> types have been moved to the +<a href="/pkg/os/">os</a> package. +</p> + +<p> +<a href="/pkg/image/draw/">Package image/draw</a> is the new name for +<code>exp/draw</code>. The GUI-related code from <code>exp/draw</code> is now +located in the <a href="/pkg/exp/gui/">exp/gui</a> package. +</p> + +<h3 id="r58.cmd">Tools</h3> + +<p> +<a href="/cmd/goinstall/">Goinstall</a> now observes the GOPATH environment +variable to build and install your own code and external libraries outside of +the Go tree (and avoid writing Makefiles). +</p> + + <h2 id="r57">r57 (released 2011/05/03)</h2> <p> diff --git a/doc/devel/roadmap.html b/doc/devel/roadmap.html index 343203cdb..d3c494715 100644 --- a/doc/devel/roadmap.html +++ b/doc/devel/roadmap.html @@ -43,8 +43,6 @@ Improved garbage collector. <li> Debugger. <li> -App Engine support. -<li> Improved implementation documentation. </ul> @@ -132,4 +130,6 @@ A means of recovering from a panic (recover). Improved CGO including some mechanism for calling back from C to Go. <li> Faster, allocation-light reflection. +<li> +App Engine support. </ul> diff --git a/doc/devel/weekly.html b/doc/devel/weekly.html index 5cb002f73..b576a910d 100644 --- a/doc/devel/weekly.html +++ b/doc/devel/weekly.html @@ -14,11 +14,344 @@ hg pull hg update weekly.<i>YYYY-MM-DD</i> </pre> +<h2 id="2011-06-09">2011-06-09 (<a href="release.html#r58">base for r58</a>)</h2> + +<pre> +This release includes changes to the strconv, http, and exp/draw packages. +Client code that uses the http or exp/draw packages will need to be changed, +and code that uses strconv or fmt's "%q" formatting directive merits checking. + +The strconv package's Quote function now escapes only those Unicode code points +not classified as printable by unicode.IsPrint. Previously Quote would escape +all non-ASCII characters. This also affects the fmt package's "%q" formatting +directive. The previous quoting behavior is still available via strconv's new +QuoteToASCII function. + +Most instances of the type map[string][]string in the http package have been +replaced with the new Values type. The http.Values type has the Get, Set, Add, +and Del helper methods to make working with query parameters and form values +more convenient. + +The exp/draw package has been split into the image/draw and exp/gui packages. + +Other changes: +* 8l, ld: initial adjustments for Plan 9 native compilation of 8l (thanks Lucio De Re). +* arm: floating point improvements (thanks Fan Hongjian). +* big: Improved speed of nat-to-string conversion (thanks Michael T. Jones), + Rat outputs the requested precision from FloatString (thanks Graham Miller), + gobs for big.Rats. +* cgo: support non intel gcc machine flags (thanks Dave Cheney). +* compress/lzw: do not use background goroutines, + reduce decoder buffer size from 3*4096 to 2*4096. +* crypto/twofish: fix Reset index overflow bug. +* crypto: reorg, cleanup and add function for generating CRLs. +* exec: export the underlying *os.Process in Cmd. +* gc: enable building under clang/2.9 (thanks Dave Cheney), + preparatory work toward escape analysis, compact stack frames. +* go/build: new incomplete package for building go programs. +* godefs: do not assume forward type references are enums (thanks Robert Hencke). +* gofix, gofmt: fix diff regression from exec change. +* html: improve attribute parsing, note package status. +* http: don't fail on accept hitting EMFILE, + fix handling of 0-length HTTP requests. +* image/draw: fix clipping bug where sp/mp were not shifted when r.Min was. +* image/gif: fix buglet in graphics extension. +* image/tiff: support for bit depths other than 8 (thanks Benny Siegert). +* ld: fix and simplify ELF symbol generation (thanks Anthony Martin) +* libmach: use the standardized format for designated initializers (thanks Jeff Hodges) +* mail: address list parsing. +* net: add network interface identification API (thanks Mikio Hara), + fix bug in net.Interfaces: handle elastic sdl_data size correctly (thanks Mikio Hara). +* netchan: added drain method to importer (thanks David Jakob Fritz). +* os: add Process.Kill and Process.Signal (thanks Evan Shaw), + fix Getenv for Plan 9 (thanks Yuval Pavel Zholkover). +* runtime: improve memmove by checking memory overlap (thanks Quan Yong Zhai), + support for Linux grsecurity systems (thanks Jonathan Mark). +* spec: handle a corner case for shifts. +* testing: check that tests and benchmarks do not affect GOMAXPROCS (thanks Dmitriy Vyukov). +* unicode: add IsPrint and related properties, general categories. +</pre> + +<h2 id="2011-06-02">2011-06-02</h2> + +<pre> +This release includes changes to the exec package that will require changes +to client code. + +The exec package has been re-designed with a more convenient and succinct API. +This code: + args := []string{"diff", "-u", "file1.txt", "file2.txt"} + p, err := exec.Run("/usr/bin/diff", args, os.Environ(), "", + exec.DevNull, exec.Pipe, exec.DevNull) + if err != nil { + return nil, err + } + var buf bytes.Buffer + io.Copy(&buf, p.Stdout) + w, err := p.Wait(0) + p.Close() + if err != nil { + return nil, err + } + return buf.Bytes(), err +can be rewritten as: + return exec.Command("diff", "-u", "file1.txt", "file2.txt").Output() +See the exec package documentation for the details ("godoc exec"). + +By setting the GOPATH environment variable you can use goinstall to build and +install your own code and external libraries outside of the Go tree (and avoid +writing Makefiles). +See the goinstall command documentation for the details ("godoc goinstall"). + +Other changes: +* 5g: alignment fixes. +* 6l, 8l: fix Mach-O binaries with many dynamic libraries. +* 8l: emit resources (.rsrc) in Windows PE. (thanks Wei Guangjing). +* asn1: fix marshalling of empty optional RawValues (thanks Mikkel Krautz). +* big: make Int and Rat implement fmt.Scanner (thanks Evan Shaw), + ~8x faster number scanning, + remove some unnecessary conversions. +* cgo: restrict #cgo directives to prevent shell expansion (thanks Gustavo Niemeyer), + support pkg-config for flags and libs (thanks Gustavo Niemeyer). +* compress/flate: fix Huffman tree bug, + do not use background goroutines. +* crypto/openpgp: add support for symmetrically encrypting files. +* crypto/tls/generate_cert.go: fix misspelling of O_CREATE. +* dashboard: send notification emails when the build breaks. +* doc: mention go/printer instead of container/vector in effective go, + put Release History link on 'Documentation' page, + put Weekly Snapshot History link on 'Contributing' page. +* encoding/base64: add DecodeString and EncodeToString. +* encoding/binary: add a non-reflect fast path for Read, + add a non-reflect fast path for Write. +* encoding/hex: add hex dumping. +* encoding/line: delete package. Its functionality is now in bufio. +* filepath: Abs must always return a clean path (thanks Gustavo Niemeyer). +* fmt: fix bug in UnreadRune, + make %q work for integers, printing a quoted character literal, + return EOF when out of input in Scan*. +* gc: check parameter declarations in interface fields (thanks Anthony Martin), + disallow ... in type conversions (thanks Anthony Martin), + do not force heap allocation on referencing outer variable in a closure, + fix m[x], _ = y.(T), + implement new shift rules, + patch y.tab.c to fix build when using Bison 2.5, + relax assignability of method receivers (thanks Anthony Martin), + typecheck the whole tree before walking. +* go/scanner: don't allow "0x" and "0X" as integers (thanks Evan Shaw). +* gobuilder: fixes for windows (thanks Alex Brainman). +* godoc: basic setup for running godoc on local app engine emulator, + display advert for the package dashboard on package list page. +* goinstall: fixes for windows (thanks Alex Brainman), + more verbose logging with -v. +* gotest, pkg/exec: use bash to run shell scripts on windows (thanks Alex Brainman). +* http/spdy: redo interfaces, flesh out implementation & frame types (thanks William Chan). +* http: Transport hook to register non-http(s) protocols, + add client+server benchmark, + catch Handler goroutine panics, + fix Set-Cookie date parsing, + have client set Content-Length when possible, + let Transport use a custom net.Dial function, + propagate Set-Cookie in reverse proxy, + ServeFile shouldn't send Content-Length when Content-Encoding is set. +* image: add a SubImage method. +* image/gif: simplify blockReader.Read. +* image/png: fix encoding of images that don't start at (0, 0). +* io, net, http: sendfile support. +* io: add ByteScanner, RuneScanner interfaces. +* ld: add -w to disable dwarf, make errors obviously from dwarf. +* mail: new package. +* mime/multipart: misc code/doc fixes. +* misc/cgo: remove reference to 'destroy' function. +* misc/emacs: don't select the mark after gofmt (thanks Eric Eisner). +* misc/gophertool: Chrome extension to aid in Go development +* misc/vim: limit Fmt command to Go buffers (thanks Yasuhiro Matsumoto). +* net: if we stop polling, remove any pending events for the socket, + update IP multicast socket options (thanks Mikio Hara). +* os: Fix test to work on Solaris, + fix Readdir(0) on EOF, + fix Readdir, Readdirnames (thanks Yuval Pavel Zholkover), + fix os.MkdirAll with backslash path separator (thanks Yasuhiro Matsumoto), + handle OpenFile flag parameter properly on Windows (thanks Alex Brainman). +* path/filepath: remove string constants. +* pkg: spelling tweaks, I-Z (thanks Robert Hencke). +* quietgcc: fix typo, respect $TMPDIR. +* runtime: do not garbage collect windows callbacks (thanks Alex Brainman), + fix mmap error return on linux (thanks Dmitry Chestnykh), + reset GOMAXPROCS during tests, + save cdecl registers in Windows SEH handler (thanks Alexey Borzenkov). +* spec: be precise with the use of the informal ellipsis and the Go token, + clarify rules for shifts. +* strconv: add QuoteRune; analogous to Quote but for runes rather than strings. +* strings: implement UnreadByte, UnreadRune. +* sync: always wake up sleeping goroutines on Cond.Signal (thanks Gustavo Niemeyer). +* sync/atomic: fix check64. +* syscall: add ProcAttr field to pass an unescaped command line on windows (thanks Vincent Vanackere), + add routing messages support for Linux and BSD (thanks Mikio Hara). +* template: fixes and clean-ups (thanks Gustavo Niemeyer). +* time: fix Format bug: midnight/noon are 12AM/PM not 0AM/PM. +* unicode: make the tables smaller. +</pre> + +<h2 id="2011-05-22">2011-05-22</h2> + +<pre> +This release includes changes to the http package that will require changes to +client code. + +The finalURL return value of the Client.Get method has been removed. +This value is now accessible via the new Request field on http.Response. +For example, this code: + + res, finalURL, err := http.Get(...) + +should be rewritten as: + + res, err := http.Get(...) + if err != nil { + // ... + } + finalURL := res.Request.URL.String() + +Uses of http.Get that assign the finalURL value to _ can be rewritten +automatically with gofix. + +This release also includes an optimization to the append function that makes it +between 2 and 5 times faster in typical use cases. + +Other changes: +* 5a, 6a, 8a, cc: remove old environment variables. +* 5c, 5g: fix build with too-smart gcc. +* 5l, 8l: add ELF symbol table to binary. +* 5l: delete pre-ARMv4 instruction implementations, other fixes. +* 6l, 8l: emit windows dwarf sections like other platforms (thanks Alex Brainman). +* 6l: fix emit windows dwarf sections (thanks Wei Guangjing). +* 8g: fix conversion from float to uint64 (thanks Anthony Martin). +* Make.cmd: create TARGDIR if necessary (thanks Gustavo Niemeyer). +* asn1: add big support. +* big: add Int methods to act on numbered bits (thanks Roger Peppe), + better support for string conversions, + support %v and # modifier, better handling of unknown formats. +* cgi: export RequestFromMap (thanks Evan Shaw), + set Request.TLS and Request.RemoteAddr for children. +* cgo: use packed struct to fix Windows behavior. +* codereview: add release branch support, + fetch metadata using JSON API, not XML scraping, + handle 'null as missing field' in rietveld json. +* compress/lzw: silently drop implied codes that are too large. +* compress/zlib: actually use provided dictionary in NewWriterDict +* crypto/openpgp: add key generation support, + change PublicKey.Serialize to include the header. +* crypto/rand: add utility functions for number generation (thanks Anthony Martin). +* crypto/tls: export the verified chains. +* crypto/x509/crl: add package. +* crypto/x509: export raw SubjectPublicKeyInfo, + support DSA public keys in X.509 certs, + support parsing and verifying DSA signatures (thanks Jonathan Allie). +* doc/roadmap: put "App Engine support" under "Done". +* doc: add I/O 2011 talks to talks/, docs.html, and front page. +* effective go: explain about values/pointers in String() example, + update to new Open signature. +* exp/draw: fast paths for drawing a YCbCr or an NRGBA onto an RGBA. +* filepath: make EvalSymlinks work on Windows (thanks Alex Brainman). +* flag: allow distinct sets of flags. +* gc: fix type switch error message for invalid cases (thanks Lorenzo Stoakes), + fix unsafe.Sizeof, + preserve original expression for errors. +* go/ast, go/doc, godoc: consider struct fields and interface methods when filtering ASTs. +* go/ast: consider anonymous fields and set Incomplete bit when filtering ASTs, + properly maintain map of package global imports. +* go/doc, godoc: when filtering for godoc, don't remove elements of a declaration. +* go/parser: accept parenthesized receive operations in select statements, + always introduce an ast.Object when declaring an identifier. +* go/printer, gofmt: fix alignment of "=" in const/var declarations, + fix formatting of expression lists (missing blank). +* go/printer: added simple performance benchmark, + make tests follow syntactic restrictions, + more accurate comment for incomplete structs/interfaces, +* go/token: faster FileSet.Position implementation. +* go/types: type checker API + testing infrastructure. +* godoc: added -index flag to enable/disable search index, + if there is no search box, don't run the respective JS code. +* gofmt: update test.sh (exclude a file w/ incorrect syntax). +* html: parse empty, unquoted, and single-quoted attribute values. +* http/cgi: correctly set request Content-Type (thanks Evan Shaw), + pass down environment variables for IRIX and Solaris. +* http/pprof: fix POST reading bug. +* http/spdy: new incomplete package (thanks Ross Light). +* http: Client.Do should follow redirects for GET and HEAD, + add Header.Write method (thanks Evan Shaw), + add Request.SetBasicAuth method, + add Transport.ProxySelector, + add http.SetCookie(ResponseWriter, *Cookie), + don't Clean query string in relative redirects, + fix FormFile nil pointer dereference on missing multipart form, + fix racy test with a simpler version, + fix two Transport gzip+persist crashes, + include Host header in requests, + make HEAD client request follow redirects (thanks Eivind Uggedal). + update cookie doc to reference new RFC 6265, + write cookies according to RFC 6265 (thanks Christian Himpel). +* image/bmp: implement a BMP decoder. +* image/gif: new package provides a GIF decoder. +* image/jpeg: decode grayscale images, not just color images. + optimizations and tweaks. +* image/png: encode paletted images with alpha channel (thanks Dmitry Chestnykh), + speed up opaque RGBA encoding. +* image/tiff: implement a decoder (thanks Benny Siegert). +* image: add type-specific Set methods and use them when decoding PNG, + make AlphaColor.Set conform to usual signature (thanks Roger Peppe), + png & jpeg encoding benchmarks. +* ld: do not emit reference to dynamic library named "", + fix alignment of rodata section on Plan 9 (thanks Anthony Martin), + make ELF binaries with no shared library dependencies static binaries. +* make.bash: remove old bash version of gotest on Windows (thanks Alex Brainman). +* make: add nuke target for C commands and libs (thanks Anthony Martin). +* mime/multipart: add FileName accessor on Part, + add Writer, + return an error on Reader EOF, not (nil, nil). +* misc/cgo/test: run tests. +* misc/emacs: use UTF-8 when invoking gofmt as a subprocess (thanks Sameer Ajmani). +* misc/vim: new Vim indentation script. +* net, http: add and make use of IP address scope identification API (thanks Mikio Hara). +* net: default to 127.0.0.1, not localhost, in TestICMP, + don't crash on unexpected DNS SRV responses, + enable SO_REUSEPORT on BSD variants (thanks Mikio Hara), + protocol family adaptive address family selection (thanks Mikio Hara), + re-enable wildcard listening (thanks Mikio Hara), + sort records returned by LookupSRV (thanks Gary Burd). +* os: make Readdir & Readdirnames return os.EOF at end, + make Setenv update C environment variables. +* reflect: allow unexported key in Value.MapIndex. +* runtime, sync/atomic: fix arm cas. +* runtime: add newline to "finalizer already set" error (thanks Albert Strasheim), + handle out-of-threads on Linux gracefully (thanks Albert Strasheim), + fix function args not checked warning on ARM (thanks Dave Cheney), + make StackSystem part of StackGuard (thanks Alexey Borzenkov), + maybe fix Windows build broken by cgo setenv CL. +* spec: clarify semantics of integer division, + clarify semantics of range clause, + fix error in production syntax, + narrow syntax for expression and select statements, + newlines cannot be used inside a char or "" string literal, + restricted expressions may still be parenthesized. +* strings: make Reader.Read use copy instead of an explicit loop. +* syscall: add Windows file mapping functions and constants (thanks Evan Shaw), + add IPv6 scope zone ID support (thanks Mikio Hara), + add netlink support for linux/386, linux/amd64, linux/arm (thanks Mikio Hara), + add Sendfile, + adjust freebsd syscalls.master URL properly (thanks Mikio Hara), + change Overlapped.HEvent type, it is a handle (thanks Alex Brainman). +* syslog: fix skipping of net tests (thanks Gustavo Niemeyer). +* template: support string, int and float literals (thanks Gustavo Niemeyer). +* xml: fix reflect error. +</pre> + <h2 id="2011-04-27">2011-04-27 (<a href="release.html#r57">base for r57</a>)</h2> <pre> This release includes revisions to the reflect package to make it more -efficient, after the last weekly’s major API update. If your code uses reflect +efficient, after the last weekly's major API update. If your code uses reflect it may require further changes, not all of which can be made automatically by gofix. For the full details of the change, see http://codereview.appspot.com/4435042 @@ -168,7 +501,7 @@ The os package's Open function has been replaced by three functions: Open(name) // same as old Open(name, O_RDONLY, 0) Create(name) // same as old Open(name, O_RDWR|O_TRUNC|O_CREAT, 0666) -To update your code to use the new APIs, run "gofix path/to/code". Gofix can’t +To update your code to use the new APIs, run "gofix path/to/code". Gofix can't handle all situations perfectly, so read and test the changes it makes before committing them. @@ -298,8 +631,8 @@ produce memory and CPU profiling data when invoked with the -test.memprofile and -test.cpuprofile flags. Run "godoc gotest" for details. We have also introduced a way for tests to run quickly when an exhaustive test -is unnecessary. Gotest’s new -test.short flag in combination with the testing -package’s new Short function allows you to write tests that can be run in +is unnecessary. Gotest's new -test.short flag in combination with the testing +package's new Short function allows you to write tests that can be run in normal or "short" mode; short mode is now used by all.bash to reduce installation time. The Makefiles know about the flag - you can just run "make testshort". diff --git a/doc/docs.html b/doc/docs.html index d4e78446f..9fd3dcebe 100644 --- a/doc/docs.html +++ b/doc/docs.html @@ -70,6 +70,12 @@ An introduction to Go for C++ programmers. <h2 id="tutorials_nonenglish">Non-English Documentation</h2> +<h3 id="docs_be">Belarusian — Беларуская</h3> + +<ul> +<li><a href="http://www.designcontest.com/show/faq-be">faq-be</a> - Frequently Asked Questions.</li> +</ul> + <h3 id="docs_cn">Chinese — 中文</h3> <ul> @@ -90,6 +96,11 @@ An introduction to Go for C++ programmers. <li><a href="http://golang.jp/">golang.jp</a> - Go documentation and news. </ul> +<h3 id="docs_kr">Korean — 한국어</h3> +<ul> +<li><a href="http://code.google.com/p/golang-korea">golang-korea</a> - Go documentation and news. +</ul> + <h3 id="docs_ru">Russian — Русский</h3> <ul> <li><a href="http://golanguage.ru/">golanguage.ru</a> - Go documentation. @@ -119,6 +130,9 @@ The built-in documentation for the Go tools. The official Go Language specification. </p> +<h3 id="release"><a href="devel/release.html">Release History</a></h3> +<p>A summary of the changes between Go releases.</p> + <h3 id="go_mem"><a href="go_mem.html">The Go Memory Model</a></h3> <p> A document that specifies the conditions under which reads of a variable in @@ -128,6 +142,22 @@ same variable in a different goroutine. <h2 id="videos_talks">Videos and Talks</h2> +<h3 id="writing_web_apps"><a href="http://www.youtube.com/watch?v=-i0hat7pdpk">Writing Web Apps in Go</a></h3> +<p> +A talk by Rob Pike and Andrew Gerrand presented at Google I/O 2011. +It walks through the construction and deployment of a simple web application +and unveils the <a href="http://blog.golang.org/2011/05/go-and-google-app-engine.html">Go runtime for App Engine</a>. +See the <a href="/doc/talks/io2011/Writing_Web_Apps_in_Go.pdf">presentation slides</a>. +</p> + +<h3 id="real_world_go"><a href="http://www.youtube.com/watch?v=7QDVRowyUQA">Real World Go</a></h3> +<p> +A talk by Andrew Gerrand presented at Google I/O Bootcamp 2011. +It gives a broad overview of Go's type system and concurrency model +and provides four examples of Go programs that solve real problems. +See the <a href="/doc/talks/io2011/Real_World_Go.pdf">presentation slides</a>. +</p> + <h3 id="go_programming"><a href="http://www.youtube.com/watch?v=jgVhBThJdXc">Go Programming</a></h3> <p> A presentation delivered by Rob Pike and Russ Cox at Google I/O 2010. It diff --git a/doc/effective_go.html b/doc/effective_go.html index a7e6b7bdf..972772d33 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -297,9 +297,9 @@ determines just which package is being used. <p> Another convention is that the package name is the base name of its source directory; -the package in <code>src/pkg/container/vector</code> -is imported as <code>"container/vector"</code> but has name <code>vector</code>, -not <code>container_vector</code> and not <code>containerVector</code>. +the package in <code>src/pkg/encoding/base64</code> +is imported as <code>"encoding/base64"</code> but has name <code>base64</code>, +not <code>encoding_base64</code> and not <code>encodingBase64</code>. </p> <p> @@ -504,7 +504,7 @@ the body ends in <code>break</code>, <code>continue</code>, </p> <pre> -f, err := os.Open(name, os.O_RDONLY, 0) +f, err := os.Open(name) if err != nil { return err } @@ -520,7 +520,7 @@ statements, the resulting code needs no <code>else</code> statements. </p> <pre> -f, err := os.Open(name, os.O_RDONLY, 0) +f, err := os.Open(name) if err != nil { return err } @@ -813,7 +813,7 @@ canonical examples are unlocking a mutex or closing a file. <pre> // Contents returns the file's contents as a string. func Contents(filename string) (string, os.Error) { - f, err := os.Open(filename, os.O_RDONLY, 0) + f, err := os.Open(filename) if err != nil { return "", err } @@ -935,13 +935,14 @@ example of its possibilities. <h2 id="data">Data</h2> -<h3 id="allocation_new">Allocation with <code>new()</code></h3> +<h3 id="allocation_new">Allocation with <code>new</code></h3> <p> -Go has two allocation primitives, <code>new()</code> and <code>make()</code>. +Go has two allocation primitives, the built-in functions +<code>new</code> and <code>make</code>. They do different things and apply to different types, which can be confusing, but the rules are simple. -Let's talk about <code>new()</code> first. +Let's talk about <code>new</code> first. It's a built-in function essentially the same as its namesakes in other languages: <code>new(T)</code> allocates zeroed storage for a new item of type <code>T</code> and returns its address, a value of type <code>*T</code>. @@ -950,9 +951,9 @@ In Go terminology, it returns a pointer to a newly allocated zero value of type </p> <p> -Since the memory returned by <code>new()</code> is zeroed, it's helpful to arrange that the +Since the memory returned by <code>new</code> is zeroed, it's helpful to arrange that the zeroed object can be used without further initialization. This means a user of -the data structure can create one with <code>new()</code> and get right to +the data structure can create one with <code>new</code> and get right to work. For example, the documentation for <code>bytes.Buffer</code> states that "the zero value for <code>Buffer</code> is an empty buffer ready to use." @@ -1065,7 +1066,7 @@ s := []string {Enone: "no error", Eio: "Eio", Einval: "invalid argument"} m := map[int]string{Enone: "no error", Eio: "Eio", Einval: "invalid argument"} </pre> -<h3 id="allocation_make">Allocation with <code>make()</code></h3> +<h3 id="allocation_make">Allocation with <code>make</code></h3> <p> Back to allocation. @@ -1099,8 +1100,8 @@ In contrast, <code>new([]int)</code> returns a pointer to a newly allocated, zer structure, that is, a pointer to a <code>nil</code> slice value. <p> -These examples illustrate the difference between <code>new()</code> and -<code>make()</code>. +These examples illustrate the difference between <code>new</code> and +<code>make</code>. </p> <pre> @@ -1116,9 +1117,9 @@ v := make([]int, 100) </pre> <p> -Remember that <code>make()</code> applies only to maps, slices and channels +Remember that <code>make</code> applies only to maps, slices and channels and does not return a pointer. -To obtain an explicit pointer allocate with <code>new()</code>. +To obtain an explicit pointer allocate with <code>new</code>. </p> <h3 id="arrays">Arrays</h3> @@ -1473,7 +1474,7 @@ map[string] int </pre> <p> If you want to control the default format for a custom type, all that's required is to define -a method <code>String() string</code> on the type. +a method with the signature <code>String() string</code> on the type. For our simple type <code>T</code>, that might look like this. </p> <pre> @@ -1489,7 +1490,13 @@ to print in the format 7/-2.35/"abc\tdef" </pre> <p> -Our <code>String()</code> method is able to call <code>Sprintf</code> because the +(If you need to print <em>values</em> of type <code>T</code> as well as pointers to <code>T</code>, +the receiver for <code>String</code> must be of value type; this example used a pointer because +that's more efficient and idiomatic for struct types. +See the section below on <a href="#pointers_vs_values">pointers vs. value receivers</a> for more information.) +</p> +<p> +Our <code>String</code> method is able to call <code>Sprintf</code> because the print routines are fully reentrant and can be used recursively. We can even go one step further and pass a print routine's arguments directly to another such routine. The signature of <code>Printf</code> uses the type <code>...interface{}</code> @@ -1677,19 +1684,20 @@ var ( <h3 id="init">The init function</h3> <p> -Finally, each source file can define its own <code>init()</code> function to -set up whatever state is required. The only restriction is that, although +Finally, each source file can define its own niladic <code>init</code> function to +set up whatever state is required. (Actually each file can have multiple +<code>init</code> functions.) The only restriction is that, although goroutines can be launched during initialization, they will not begin execution until it completes; initialization always runs as a single thread of execution. -And finally means finally: <code>init()</code> is called after all the +And finally means finally: <code>init</code> is called after all the variable declarations in the package have evaluated their initializers, and those are evaluated only after all the imported packages have been initialized. </p> <p> Besides initializations that cannot be expressed as declarations, -a common use of <code>init()</code> functions is to verify or repair +a common use of <code>init</code> functions is to verify or repair correctness of the program state before real execution begins. </p> @@ -1893,7 +1901,7 @@ on every instance of a common method. In such cases, the constructor should return an interface value rather than the implementing type. As an example, in the hash libraries -both <code>crc32.NewIEEE()</code> and <code>adler32.New()</code> +both <code>crc32.NewIEEE</code> and <code>adler32.New</code> return the interface type <code>hash.Hash32</code>. Substituting the CRC-32 algorithm for Adler-32 in a Go program requires only changing the constructor call; @@ -2675,7 +2683,7 @@ field for recoverable failures. <pre> for try := 0; try < 2; try++ { - file, err = os.Open(filename, os.O_RDONLY, 0) + file, err = os.Open(filename) if err == nil { return } diff --git a/doc/frontpage.css b/doc/frontpage.css index bcdca6401..299855ce9 100644 --- a/doc/frontpage.css +++ b/doc/frontpage.css @@ -80,6 +80,9 @@ span.keyword { #content-videos .thumbnail._004 { background: url(/doc/video-004.png); } +#content-videos .thumbnail._005 { + background: url(/doc/video-005.jpg); +} #content-videos a.video { display: inline-block; width: 150px; diff --git a/doc/go_faq.html b/doc/go_faq.html index 5f92b0528..560ab3617 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -26,6 +26,7 @@ are not well supported by popular systems languages. <li> The emergence of multicore computers has generated worry and confusion. </ul> +</p> <p> We believe it's worth trying again with a new language, a concurrent, @@ -49,12 +50,14 @@ concurrent execution and communication. By its design, Go proposes an approach for the construction of system software on multicore machines. </ul> +</p> <h3 id="What_is_the_origin_of_the_name"> What is the origin of the name?</h3> <p> “Ogle” would be a good name for a Go debugger. +</p> <h3 id="Whats_the_origin_of_the_mascot"> What's the origin of the mascot?</h3> @@ -83,6 +86,7 @@ http://plan9.bell-labs.com/sys/doc/compiler.html</a> <code>6</code> is the architecture letter for amd64 (or x86-64, if you prefer), while <code>g</code> stands for Go. +</p> <h3 id="history"> What is the history of the project?</h3> @@ -104,7 +108,6 @@ and libraries from prototype to reality. Many others have contributed ideas, discussions, and code. </p> - <h3 id="creating_a_new_language"> Why are you creating a new language?</h3> <p> @@ -117,6 +120,7 @@ language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java. </p> + <p> Go is an attempt to combine the ease of programming of an interpreted, dynamically typed @@ -131,7 +135,6 @@ and so on. These cannot be addressed well by libraries or tools; a new language was called for. </p> - <h3 id="ancestors"> What are Go's ancestors?</h3> <p> @@ -147,7 +150,6 @@ about what programmers do and how to make programming, at least the kind of programming we do, more effective, which means more fun. </p> - <h3 id="principles"> What are the guiding principles in the design?</h3> <p> @@ -179,26 +181,17 @@ interfaces represent abstraction; and so on. Orthogonality makes it easier to understand what happens when things combine. </p> - <h2 id="Usage">Usage</h2> -<h3 id="Who_should_use_the_language"> -Who should use the language?</h3> - -<p> -Go is an experiment. We hope adventurous users will give it a try and see -if they enjoy it. Not every programmer -will, but we hope enough will find satisfaction in the approach it -offers to justify further development. - <h3 id="Is_Google_using_go_internally"> Is Google using Go internally?</h3> -<p>Yes. There are now several Go programs deployed in +<p> +Yes. There are now several Go programs deployed in production inside Google. For instance, the server behind <a href="http://golang.org">http://golang.org</a> is a Go program; in fact it's just the <a href="/cmd/godoc"><code>godoc</code></a> document server running in a production configuration. - +</p> <h3 id="Do_Go_programs_link_with_Cpp_programs"> Do Go programs link with C/C++ programs?</h3> @@ -211,11 +204,14 @@ therefore only be linked with C programs using the same convention. There is such a C compiler but no C++ compiler. <code>Gccgo</code> is a GCC front-end that can, with care, be linked with GCC-compiled C or C++ programs. +</p> <p> The <a href="/cmd/cgo/">cgo</a> program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries. +</p> + <h3 id="Does_Go_support_Google_protocol_buffers"> Does Go support Google's protocol buffers?</h3> @@ -226,6 +222,7 @@ It is available at <a href="http://code.google.com/p/goprotobuf/">http://code.google.com/p/goprotobuf/</a> </p> + <h3 id="Can_I_translate_the_Go_home_page"> Can I translate the Go home page into another language?</h3> @@ -277,11 +274,13 @@ such as concurrency and garbage collection. Your favorite feature may be missing because it doesn't fit, because it affects compilation speed or clarity of design, or because it would make the fundamental system model too difficult. +</p> <p> If it bothers you that Go is missing feature <var>X</var>, please forgive us and investigate the features that Go does have. You might find that they compensate in interesting ways for the lack of <var>X</var>. +</p> <h3 id="generics"> Why does Go not have generic types?</h3> @@ -289,6 +288,7 @@ Why does Go not have generic types?</h3> Generics may well be added at some point. We don't feel an urgency for them, although we understand some programmers do. </p> + <p> Generics are convenient but they come at a cost in complexity in the type system and run-time. We haven't yet found a @@ -298,6 +298,7 @@ plus the ability to use the empty interface to construct containers (with explicit unboxing) mean in many cases it is possible to write code that does what generics would enable, if less smoothly. </p> + <p> This remains an open issue. </p> @@ -311,6 +312,7 @@ convoluted code. It also tends to encourage programmers to label too many ordinary errors, such as failing to open a file, as exceptional. </p> + <p> Go takes a different approach. Instead of exceptions, it has a couple of built-in functions to signal and recover from truly exceptional @@ -319,11 +321,11 @@ function's state being torn down after an error, which is sufficient to handle catastrophe but requires no extra control structures and, when used well, can result in clean error-handling code. </p> + <p> See the <a href="http://blog.golang.org/2010/08/defer-panic-and-recover.html">Defer, Panic, and Recover</a> article for details. </p> - <h3 id="assertions"> Why does Go not have assertions?</h3> @@ -336,6 +338,7 @@ Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code. +</p> <p> The same arguments apply to the use of <code>assert()</code> in test programs. Proper @@ -348,17 +351,20 @@ answer for 2 and therefore no more tests were run. The programmer who triggers the test failure may not be familiar with the code that fails. Time invested writing a good error message now pays off later when the test breaks. +</p> <p> In testing, if the amount of extra code required to write good errors seems repetitive and overwhelming, it might work better as a table-driven test instead. Go has excellent support for data structure literals. +</p> <p> We understand that this is a point of contention. There are many things in the Go language and libraries that differ from modern practices, simply because we feel it's sometimes worth trying a different approach. +</p> <h3 id="csp"> Why build concurrency on the ideas of CSP?</h3> @@ -370,6 +376,7 @@ such as mutexes, condition variables, and even memory barriers. Higher-level interfaces enable much simpler code, even if there are still mutexes and such under the covers. </p> + <p> One of the most successful models for providing high-level linguistic support for concurrency comes from Hoare's Communicating Sequential Processes, or CSP. @@ -392,6 +399,7 @@ The result, which we call goroutines, can be very cheap: unless they spend a lot in long-running system calls, they cost little more than the memory for the stack. </p> + <p> To make the stacks small, Go's run-time uses segmented stacks. A newly minted goroutine is given a few kilobytes, which is almost always enough. @@ -420,7 +428,6 @@ as when hosting an untrusted program, the implementation could interlock map access. </p> - <h2 id="types">Types</h2> <h3 id="Is_Go_an_object-oriented_language"> @@ -435,10 +442,12 @@ also ways to embed types in other types to provide something analogous—but not identical—to subclassing. Moreover, methods in Go are more general than in C++ or Java: they can be defined for any sort of data, not just structs. +</p> <p> Also, the lack of type hierarchy makes “objects” in Go feel much more lightweight than in languages such as C++ or Java. +</p> <h3 id="How_do_I_get_dynamic_dispatch_of_methods"> How do I get dynamic dispatch of methods?</h3> @@ -446,6 +455,7 @@ How do I get dynamic dispatch of methods?</h3> <p> The only way to have dynamically dispatched methods is through an interface. Methods on structs or other types are always resolved statically. +</p> <h3 id="inheritance"> Why is there no type inheritance?</h3> @@ -455,6 +465,7 @@ involves too much discussion of the relationships between types, relationships that often could be derived automatically. Go takes a different approach. </p> + <p> Rather than requiring the programmer to declare ahead of time that two types are related, in Go a type automatically satisfies any interface @@ -469,6 +480,7 @@ or for testing—without annotating the original types. Because there are no explicit relationships between types and interfaces, there is no type hierarchy to manage or discuss. </p> + <p> It's possible to use these ideas to construct something analogous to type-safe Unix pipes. For instance, see how <code>fmt.Fprintf</code> @@ -479,6 +491,7 @@ stream ciphers. All these ideas stem from a single interface (<code>io.Writer</code>) representing a single method (<code>Write</code>). And that's only scratching the surface. </p> + <p> It takes some getting used to but this implicit style of type dependency is one of the most exciting things about Go. @@ -503,6 +516,7 @@ but that it could also be confusing and fragile in practice. Matching only by n and requiring consistency in the types was a major simplifying decision in Go's type system. </p> + <p> Regarding operator overloading, it seems more a convenience than an absolute requirement. Again, things are simpler without it. @@ -574,6 +588,23 @@ the interface idea. Sometimes, though, they're necessary to resolve ambiguities among similar interfaces. </p> +<h3 id="convert_slice_of_interface"> +Can I convert a []T to an []interface{}?</h3> + +<p> +Not directly because they do not have the same representation in memory. +It is necessary to copy the elements individually to the destination +slice. This example converts a slice of <code>int</code> to a slice of +<code>interface{}</code>: +</p> + +<pre> +t := []int{1, 2, 3, 4} +s := make([]interface{}, len(t)) +for i, v := range t { + s[i] = v +} +</pre> <h2 id="values">Values</h2> @@ -592,6 +623,7 @@ The definition of constants in Go—arbitrary precision values free of signedness and size annotations—ameliorates matters considerably, though. </p> + <p> A related detail is that, unlike in C, <code>int</code> and <code>int64</code> are distinct types even if <code>int</code> is a 64-bit type. The <code>int</code> @@ -610,7 +642,6 @@ If a specific application can benefit from a custom implementation, it's possibl to write one but it will not be as convenient syntactically; this seems a reasonable tradeoff. </p> - <h3 id="map_keys"> Why don't maps allow structs and arrays as keys?</h3> <p> @@ -637,7 +668,6 @@ language but they have a large effect on usability: Go became a more productive, comfortable language when they were introduced. </p> - <h2 id="Writing_Code">Writing Code</h2> <h3 id="How_are_libraries_documented"> @@ -650,6 +680,7 @@ command line or on the web. An instance is running at <a href="http://golang.org/pkg/">http://golang.org/pkg/</a>. In fact, <code>godoc</code> implements the full site at <a href="http://golang.org/">http://golang.org/</a>. +</p> <h3 id="Is_there_a_Go_programming_style_guide"> Is there a Go programming style guide?</h3> @@ -663,6 +694,7 @@ More directly, the program <code>gofmt</code> is a pretty-printer whose purpose is to enforce layout rules; it replaces the usual compendium of do's and don'ts that allows interpretation. All the Go code in the repository has been run through <code>gofmt</code>. +</p> <h3 id="How_do_I_submit_patches_to_the_Go_libraries"> How do I submit patches to the Go libraries?</h3> @@ -670,12 +702,13 @@ How do I submit patches to the Go libraries?</h3> <p> The library sources are in <code>go/src/pkg</code>. If you want to make a significant change, please discuss on the mailing list before embarking. +</p> <p> See the document <a href="contribute.html">Contributing to the Go project</a> for more information about how to proceed. - +</p> <h2 id="Pointers">Pointers and Allocation</h2> @@ -751,6 +784,7 @@ From a correctness standpoint, you don't need to know. Each variable in Go exists as long as there are references to it. The storage location chosen by the implementation is irrelevant to the semantics of the language. +</p> <p> The storage location does have an effect on writing efficient programs. @@ -759,11 +793,13 @@ local to a function in that function's stack frame. However, if the compiler cannot prove that the variable is not referenced after the function returns, then the compiler must allocate the variable on the garbage-collected heap to avoid dangling pointer errors. +</p> <p> In the current compilers, the analysis is crude: if a variable has its address taken, that variable is allocated on the heap. We are working to improve this analysis so that more data is kept on the stack. +</p> <h2 id="Concurrency">Concurrency</h2> @@ -830,7 +866,6 @@ should recognize such cases and optimize its use of OS threads. For now, <code>GOMAXPROCS</code> should be set on a per-application basis. </p> - <h2 id="Functions_methods">Functions and Methods</h2> <h3 id="different_method_sets"> @@ -994,6 +1029,7 @@ standard GCC back end. <code>Gc</code> is written in C using Although it's a new program, it fits in the Plan 9 C compiler suite (<a href="http://plan9.bell-labs.com/sys/doc/compiler.html">http://plan9.bell-labs.com/sys/doc/compiler.html</a>) and uses a variant of the Plan 9 loader to generate ELF binaries. +</p> <p> We considered writing <code>6g</code>, the original Go compiler, in Go itself but @@ -1003,10 +1039,12 @@ set up a Go environment. <code>Gccgo</code>, which came later, makes it possible consider writing a compiler in Go, which might well happen. (Go would be a fine language in which to implement a compiler; a native lexer and parser are already available in <a href="/pkg/go/"><code>/pkg/go</code></a>.) +</p> <p> We also considered using LLVM for <code>6g</code> but we felt it was too large and slow to meet our performance goals. +</p> <h3 id="How_is_the_run_time_support_implemented"> How is the run-time support implemented?</h3> @@ -1021,6 +1059,7 @@ compiled with a version of the Plan 9 C compiler that supports segmented stacks for goroutines. Work is underway to provide the same stack management in <code>gccgo</code>. +</p> <h3 id="Why_is_my_trivial_program_such_a_large_binary"> Why is my trivial program such a large binary?</h3> @@ -1030,12 +1069,14 @@ The gc tool chain (<code>5l</code>, <code>6l</code>, and <code>8l</code>) only generate statically linked binaries. All Go binaries therefore include the Go run-time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces. +</p> <p> A trivial C "hello, world" program compiled and linked statically using gcc on Linux is around 750 kB. An equivalent Go program is around 1.1 MB, but that includes more powerful run-time support. We believe that with some effort the size of Go binaries can be reduced. +</p> <h2 id="Performance">Performance</h2> @@ -1070,7 +1111,6 @@ isn't fast enough yet (even if it were, taking care not to generate unnecessary garbage can have a huge effect). </p> - <h2 id="change_from_c">Changes from C</h2> <h3 id="different_syntax"> @@ -1169,6 +1209,7 @@ This works very well in practice but has the effect that it forces a brace style. For instance, the opening brace of a function cannot appear on a line by itself. </p> + <p> Some have argued that the lexer should do lookahead to permit the brace to live on the next line. We disagree. Since Go code is meant @@ -1195,6 +1236,7 @@ implement it with low enough overhead and no significant latency. (The current implementation is a plain mark-and-sweep collector but a replacement is in the works.) </p> + <p> Another point is that a large part of the difficulty of concurrent and multi-threaded programming is memory management; @@ -1205,8 +1247,8 @@ Of course, implementing garbage collection in a concurrent environment is itself a challenge, but meeting it once rather than in every program helps everyone. </p> + <p> Finally, concurrency aside, garbage collection makes interfaces simpler because they don't need to specify how memory is managed across them. </p> - diff --git a/doc/go_mem.html b/doc/go_mem.html index da45a07d7..906b858e8 100644 --- a/doc/go_mem.html +++ b/doc/go_mem.html @@ -1,5 +1,14 @@ <!-- The Go Memory Model --> +<style> +p.rule { + font-style: italic; +} +span.event { + font-style: italic; +} +</style> + <h2>Introduction</h2> <p> @@ -214,6 +223,17 @@ the <code>print</code>. </p> <p class="rule"> +The closing of a channel happens before a receive that returns a zero value +because the channel is closed. +</p> + +<p> +In the previous example, replacing +<code>c <- 0</code> with <code>close(c)</code> +yields a program with the same guaranteed behavior. +</p> + +<p class="rule"> A receive from an unbuffered channel happens before the send on that channel completes. </p> diff --git a/doc/go_spec.html b/doc/go_spec.html index 886f89d12..abf5b8f50 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ <!-- title The Go Programming Language Specification --> -<!-- subtitle Version of Apr 22, 2011 --> +<!-- subtitle Version of June 7, 2011 --> <!-- TODO @@ -10,7 +10,6 @@ TODO [ ] clarify what a field name is in struct declarations (struct{T} vs struct {T T} vs struct {t T}) [ ] need explicit language about the result type of operations -[ ] may want to have some examples for the types of shift operations [ ] should string(1<<s) and float32(1<<s) be valid? [ ] should probably write something about evaluation order of statements even though obvious @@ -46,10 +45,10 @@ The syntax is specified using Extended Backus-Naur Form (EBNF): </p> <pre class="grammar"> -Production = production_name "=" Expression "." . +Production = production_name "=" [ Expression ] "." . Expression = Alternative { "|" Alternative } . Alternative = Term { Term } . -Term = production_name | token [ "..." token ] | Group | Option | Repetition . +Term = production_name | token [ "…" token ] | Group | Option | Repetition . Group = "(" Expression ")" . Option = "[" Expression "]" . Repetition = "{" Expression "}" . @@ -73,8 +72,12 @@ double quotes <code>""</code> or back quotes <code>``</code>. </p> <p> -The form <code>a ... b</code> represents the set of characters from -<code>a</code> through <code>b</code> as alternatives. +The form <code>a … b</code> represents the set of characters from +<code>a</code> through <code>b</code> as alternatives. The horizontal +ellipis … is also used elsewhere in the spec to informally denote various +enumerations or code snippets that are not further specified. The character … +(as opposed to the three characters <code>...</code>) is not a token of the Go +language. </p> <h2 id="Source_code_representation">Source code representation</h2> @@ -102,7 +105,8 @@ compiler may disallow the NUL character (U+0000) in the source text. The following terms are used to denote specific Unicode character classes: </p> <pre class="ebnf"> -unicode_char = /* an arbitrary Unicode code point */ . +newline = /* the Unicode code point U+000A */ . +unicode_char = /* an arbitrary Unicode code point except newline */ . unicode_letter = /* a Unicode code point classified as "Letter" */ . unicode_digit = /* a Unicode code point classified as "Decimal Digit" */ . </pre> @@ -122,9 +126,9 @@ The underscore character <code>_</code> (U+005F) is considered a letter. </p> <pre class="ebnf"> letter = unicode_letter | "_" . -decimal_digit = "0" ... "9" . -octal_digit = "0" ... "7" . -hex_digit = "0" ... "9" | "A" ... "F" | "a" ... "f" . +decimal_digit = "0" … "9" . +octal_digit = "0" … "7" . +hex_digit = "0" … "9" | "A" … "F" | "a" … "f" . </pre> <h2 id="Lexical_elements">Lexical elements</h2> @@ -286,7 +290,7 @@ An optional prefix sets a non-decimal base: <code>0</code> for octal, <code>0x</ </p> <pre class="ebnf"> int_lit = decimal_lit | octal_lit | hex_lit . -decimal_lit = ( "1" ... "9" ) { decimal_digit } . +decimal_lit = ( "1" … "9" ) { decimal_digit } . octal_lit = "0" { octal_digit } . hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } . </pre> @@ -471,7 +475,7 @@ U+00FF. <pre class="ebnf"> string_lit = raw_string_lit | interpreted_string_lit . -raw_string_lit = "`" { unicode_char } "`" . +raw_string_lit = "`" { unicode_char | newline } "`" . interpreted_string_lit = `"` { unicode_value | byte_value } `"` . </pre> @@ -821,7 +825,7 @@ make([]T, length, capacity) </pre> <p> -The <code>make()</code> call allocates a new, hidden array to which the returned +A call to <code>make</code> allocates a new, hidden array to which the returned slice value refers. That is, executing </p> @@ -1053,9 +1057,9 @@ have the method set </p> <pre> -func (p T) Read(b Buffer) bool { return ... } -func (p T) Write(b Buffer) bool { return ... } -func (p T) Close() { ... } +func (p T) Read(b Buffer) bool { return … } +func (p T) Write(b Buffer) bool { return … } +func (p T) Close() { … } </pre> <p> @@ -1093,8 +1097,8 @@ If <code>S1</code> and <code>S2</code> also implement </p> <pre> -func (p T) Lock() { ... } -func (p T) Unlock() { ... } +func (p T) Lock() { … } +func (p T) Unlock() { … } </pre> <p> @@ -1173,8 +1177,9 @@ make(map[string] int, 100) <p> The initial capacity does not bound its size: maps grow to accommodate the number of items -stored in them. -</p> +stored in them, with the exception of <code>nil</code> maps. +A <code>nil</code> map is equivalent to an empty map except that no elements +may be added. <h3 id="Channel_types">Channel types</h3> @@ -1233,6 +1238,7 @@ succeed without blocking if the buffer is not full (sends) or not empty (receive and elements are received in the order they are sent. If the capacity is zero or absent, the communication succeeds only when both a sender and receiver are ready. +A <code>nil</code> channel is never ready for communication. </p> <p> @@ -1693,7 +1699,7 @@ of an interface type or of elements of a composite type remains unchanged: </p> <pre> -// A Mutex is a data type with two methods Lock and Unlock. +// A Mutex is a data type with two methods, Lock and Unlock. type Mutex struct { /* Mutex fields */ } func (m *Mutex) Lock() { /* Lock implementation */ } func (m *Mutex) Unlock() { /* Unlock implementation */ } @@ -1967,11 +1973,11 @@ package, which means that it must begin with a Unicode upper case letter. math.Sin </pre> -<!--- +<!-- <p> <span class="alert">TODO: Unify this section with Selectors - it's the same syntax.</span> </p> ----> +--> <h3 id="Composite_literals">Composite literals</h3> @@ -2096,7 +2102,7 @@ element index plus one. A slice literal has the form </p> <pre> -[]T{x1, x2, ... xn} +[]T{x1, x2, … xn} </pre> <p> @@ -2104,7 +2110,7 @@ and is a shortcut for a slice operation applied to an array literal: </p> <pre> -[n]T{x1, x2, ... xn}[0 : n] +[n]T{x1, x2, … xn}[0 : n] </pre> <p> @@ -2130,8 +2136,8 @@ parentheses. </p> <pre> -if x == (T{a,b,c}[i]) { ... } -if (x == T{a,b,c}[i]) { ... } +if x == (T{a,b,c}[i]) { … } +if (x == T{a,b,c}[i]) { … } </pre> <p> @@ -2335,11 +2341,11 @@ p.M0 // ((*p).T0).M0 </pre> -<!--- +<!-- <span class="alert"> TODO: Specify what happens to receivers. </span> ----> +--> <h3 id="Indexes">Indexes</h3> @@ -2368,7 +2374,7 @@ or for <code>a</code> of type <code>S</code> where <code>S</code> is a <a href=" <li><code>x</code> must be an integer value and <code>0 <= x < len(a)</code></li> <li><code>a[x]</code> is the array element at index <code>x</code> and the type of <code>a[x]</code> is the element type of <code>A</code></li> - <li>if the index <code>x</code> is out of range, + <li>if <code>a</code> is <code>nil</code> or if the index <code>x</code> is out of range, a <a href="#Run_time_panics">run-time panic</a> occurs</li> </ul> @@ -2396,7 +2402,7 @@ where <code>M</code> is a <a href="#Map_types">map type</a>: <li>if the map contains an entry with key <code>x</code>, <code>a[x]</code> is the map value with key <code>x</code> and the type of <code>a[x]</code> is the value type of <code>M</code></li> - <li>if the map does not contain such an entry, + <li>if the map is <code>nil</code> or does not contain such an entry, <code>a[x]</code> is the <a href="#The_zero_value">zero value</a> for the value type of <code>M</code></li> </ul> @@ -2425,7 +2431,7 @@ where the result of the index expression is a pair of values with types </p> <p> -Similarly, if an assignment to a map has the special form +Similarly, if an assignment to a map element has the special form </p> <pre> @@ -2439,6 +2445,11 @@ the entry for key <code>x</code> is deleted from the map; if a regular assignment to an element of the map. </p> +<p> +Assigning to an element of a <code>nil</code> map causes a +<a href="#Run_time_panics">run-time panic</a>. +</p> + <h3 id="Slices">Slices</h3> @@ -2559,11 +2570,11 @@ Given an expression <code>f</code> of function type </p> <pre> -f(a1, a2, ... an) +f(a1, a2, … an) </pre> <p> -calls <code>f</code> with arguments <code>a1, a2, ... an</code>. +calls <code>f</code> with arguments <code>a1, a2, … an</code>. Except for one special case, arguments must be single-valued expressions <a href="#Assignability">assignable</a> to the parameter types of <code>F</code> and are evaluated before the function is called. @@ -2642,7 +2653,7 @@ arguments bound to the final parameter and may differ for each call site. Given the function and call </p> <pre> -func Greeting(prefix string, who ... string) +func Greeting(prefix string, who ...string) Greeting("hello:", "Joe", "Anna", "Eileen") </pre> @@ -2693,42 +2704,39 @@ unary_op = "+" | "-" | "!" | "^" | "*" | "&" | "<-" . <p> Comparisons are discussed <a href="#Comparison_operators">elsewhere</a>. For other binary operators, the operand types must be <a href="#Type_identity">identical</a> -unless the operation involves channels, shifts, or untyped <a href="#Constants">constants</a>. +unless the operation involves shifts or untyped <a href="#Constants">constants</a>. For operations involving constants only, see the section on <a href="#Constant_expressions">constant expressions</a>. </p> <p> -In a channel send, the first operand is always a channel and the second -must be a value <a href="#Assignability">assignable</a> -to the channel's element type. -</p> - -<p> -Except for shift operations, -if one operand is an untyped <a href="#Constants">constant</a> +Except for shift operations, if one operand is an untyped <a href="#Constants">constant</a> and the other operand is not, the constant is <a href="#Conversions">converted</a> to the type of the other operand. </p> <p> -The right operand in a shift operation must have unsigned integer type +The right operand in a shift expression must have unsigned integer type or be an untyped constant that can be converted to unsigned integer type. -</p> - -<p> -If the left operand of a non-constant shift operation is an untyped constant, -the type of constant is what it would be if the shift operation were replaced by -the left operand alone. +If the left operand of a non-constant shift expression is an untyped constant, +the type of the constant is what it would be if the shift expression were +replaced by its left operand alone; the type is <code>int</code> if it cannot +be determined from the context (for instance, if the shift expression is an +operand in a comparison against an untyped constant). </p> <pre> var s uint = 33 -var i = 1<<s // 1 has type int -var j = int32(1<<s) // 1 has type int32; j == 0 -var u = uint64(1<<s) // 1 has type uint64; u == 1<<33 -var f = float32(1<<s) // illegal: 1 has type float32, cannot shift -var g = float32(1<<33) // legal; 1<<33 is a constant shift operation; g == 1<<33 +var i = 1<<s // 1 has type int +var j int32 = 1<<s // 1 has type int32; j == 0 +var k = uint64(1<<s) // 1 has type uint64; k == 1<<33 +var m int = 1.0<<s // legal: 1.0 has type int +var n = 1.0<<s != 0 // legal: 1.0 has type int; n == false if ints are 32bits in size +var o = 1<<s == 2<<s // legal: 1 and 2 have type int; o == true if ints are 32bits in size +var p = 1<<s == 1<<33 // illegal if ints are 32bits in size: 1 has type int, but 1<<33 overflows int +var u = 1.0<<s // illegal: 1.0 has type float64, cannot shift +var v float32 = 1<<s // illegal: 1 has type float32, cannot shift +var w int64 = 1.0<<33 // legal: 1.0<<33 is a constant shift expression </pre> <h3 id="Operator_precedence">Operator precedence</h3> @@ -2808,15 +2816,18 @@ s += " and good bye" String addition creates a new string by concatenating the operands. </p> <p> -For integer values, <code>/</code> and <code>%</code> satisfy the following relationship: +For two integer values <code>x</code> and <code>y</code>, the integer quotient +<code>q = x / y</code> and remainder <code>r = x % y</code> satisfy the following +relationships: </p> <pre> -(a / b) * b + a % b == a +x = q*y + r and |r| < |y| </pre> <p> -with <code>(a / b)</code> truncated towards zero. +with <code>x / y</code> truncated towards zero +(<a href="http://en.wikipedia.org/wiki/Modulo_operation">"truncated division"</a>). </p> <pre> @@ -2828,6 +2839,20 @@ with <code>(a / b)</code> truncated towards zero. </pre> <p> +As an exception to this rule, if the dividend <code>x</code> is the most +negative value for the int type of <code>x</code>, the quotient +<code>q = x / -1</code> is equal to <code>x</code> (and <code>r = 0</code>). +</p> + +<pre> + x, q +int8 -128 +int16 -32768 +int32 -2147483648 +int64 -9223372036854775808 +</pre> + +<p> If the divisor is zero, a <a href="#Run_time_panics">run-time panic</a> occurs. If the dividend is positive and the divisor is a constant power of 2, the division may be replaced by a right shift, and computing the remainder may @@ -2843,8 +2868,8 @@ be replaced by a bitwise "and" operation: <p> The shift operators shift the left operand by the shift count specified by the right operand. They implement arithmetic shifts if the left operand is a signed -integer and logical shifts if it is an unsigned integer. The shift count must -be an unsigned integer. There is no upper limit on the shift count. Shifts behave +integer and logical shifts if it is an unsigned integer. +There is no upper limit on the shift count. Shifts behave as if the left operand is shifted <code>n</code> times by 1 for a shift count of <code>n</code>. As a result, <code>x << 1</code> is the same as <code>x*2</code> @@ -3025,6 +3050,7 @@ For an operand <code>ch</code> of <a href="#Channel_types">channel type</a>, the value of the receive operation <code><-ch</code> is the value received from the channel <code>ch</code>. The type of the value is the element type of the channel. The expression blocks until a value is available. +Receiving from a <code>nil</code> channel blocks forever. </p> <pre> @@ -3052,17 +3078,12 @@ or is a <a href="#The_zero_value">zero value</a> returned because the channel is closed and empty (<code>false</code>). </p> -<p> -Receiving from a <code>nil</code> channel causes a -<a href="#Run_time_panics">run-time panic</a>. -</p> - -<!--- +<!-- <p> <span class="alert">TODO: Probably in a separate section, communication semantics need to be presented regarding send, receive, select, and goroutines.</span> </p> ----> +--> <h3 id="Method_expressions">Method expressions</h3> @@ -3360,21 +3381,35 @@ respectively. Except for shift operations, if the operands of a binary operation are an untyped integer constant and an untyped floating-point constant, the integer constant is converted to an untyped floating-point constant (relevant for <code>/</code> and <code>%</code>). -Similarly, -untyped integer or floating-point constants may be used as operands +Similarly, untyped integer or floating-point constants may be used as operands wherever it is legal to use an operand of complex type; the integer or floating point constant is converted to a complex constant with a zero imaginary part. </p> <p> -Applying an operator to untyped constants results in an untyped +A constant <a href="#Comparison_operators">comparison</a> always yields +a constant of type <code>bool</code>. If the left operand of a constant +<a href="#Operators">shift expression</a> is an untyped constant, the +result is an integer constant; otherwise it is a constant of the same +type as the left operand, which must be of integer type +(§<a href="#Arithmetic_operators">Arithmetic operators</a>). +Applying all other operators to untyped constants results in an untyped constant of the same kind (that is, a boolean, integer, floating-point, -complex, or string constant), except for -<a href="#Comparison_operators">comparison operators</a>, which result in -a constant of type <code>bool</code>. +complex, or string constant). </p> +<pre> +const a = 2 + 3.0 // a == 5.0 (floating-point constant) +const b = 15 / 4 // b == 3 (integer constant) +const c = 15 / 4.0 // c == 3.75 (floating-point constant) +const d = 1 << 3.0 // d == 8 (integer constant) +const e = 1.0 << 3 // e == 8 (integer constant) +const f = int32(1) << 33 // f == 0 (type int32) +const g = float64(2) >> 1 // illegal (float64(2) is a typed floating-point constant) +const h = "foo" > "bar" // h == true (type bool) +</pre> + <p> Imaginary literals are untyped complex constants (with zero real part) and may be combined in binary @@ -3431,7 +3466,7 @@ int8(^1) // same as int8(-2) ^int8(1) // same as -1 ^ int8(1) = -2 </pre> -<!--- +<!-- <p> <span class="alert"> TODO: perhaps ^ should be disallowed on non-uints instead of assuming twos complement. @@ -3439,7 +3474,7 @@ Also it may be possible to make typed constants more like variables, at the cost overflow etc. errors being caught. </span> </p> ----> +--> <h3 id="Order_of_evaluation">Order of evaluation</h3> @@ -3522,10 +3557,9 @@ Error: log.Panic("error encountered") <p> Function calls, method calls, and receive operations -can appear in statement context. +can appear in statement context. Such statements may be parenthesized. </p> - <pre class="ebnf"> ExpressionStmt = Expression . </pre> @@ -3534,6 +3568,7 @@ ExpressionStmt = Expression . h(x+y) f.Close() <-ch +(<-ch) </pre> @@ -3557,17 +3592,13 @@ begins. Communication blocks until the send can proceed, at which point the value is transmitted on the channel. A send on an unbuffered channel can proceed if a receiver is ready. A send on a buffered channel can proceed if there is room in the buffer. +A send on a <code>nil</code> channel blocks forever. </p> <pre> ch <- 3 </pre> -<p> -Sending to a <code>nil</code> channel causes a -<a href="#Run_time_panics">run-time panic</a>. -</p> - <h3 id="IncDec_statements">IncDec statements</h3> @@ -3604,15 +3635,15 @@ assign_op = [ add_op | mul_op ] "=" . <p> Each left-hand side operand must be <a href="#Address_operators">addressable</a>, -a map index expression, -or the <a href="#Blank_identifier">blank identifier</a>. +a map index expression, or the <a href="#Blank_identifier">blank identifier</a>. +Operands may be parenthesized. </p> <pre> x = 1 *p = f() a[i] = 23 -k = <-ch +(k) = <-ch // same as: k = <-ch </pre> <p> @@ -3966,10 +3997,14 @@ As with an assignment, the operands on the left must be <a href="#Address_operators">addressable</a> or map index expressions; they denote the iteration variables. If the range expression is a channel, only one iteration variable is permitted, otherwise there may be one or two. +If the second iteration variable is the <a href="#Blank_identifier">blank identifier</a>, +the range clause is equivalent to the same clause with only the first variable present. </p> <p> -The range expression is evaluated once before beginning the loop. +The range expression is evaluated once before beginning the loop +except if the expression is an array, in which case, depending on +the expression, it might not be evaluated (see below). Function calls on the left are evaluated once per iteration. For each iteration, iteration values are produced as follows: </p> @@ -3985,8 +4020,11 @@ channel c chan E element e E <ol> <li> -For an array or slice value, the index iteration values are produced in -increasing order, starting at element index 0. +For an array, pointer to array, or slice value <code>a</code>, the index iteration +values are produced in increasing order, starting at element index 0. As a special +case, if only the first iteration variable is present, the range loop produces +iteration values from 0 up to <code>len(a)</code> and does not index into the array +or slice itself. For a <code>nil</code> slice, the number of iterations is 0. </li> <li> @@ -4005,13 +4043,14 @@ The iteration order over maps is not specified. If map entries that have not yet been reached are deleted during iteration, the corresponding iteration values will not be produced. If map entries are inserted during iteration, the behavior is implementation-dependent, but the -iteration values for each entry will be produced at most once. +iteration values for each entry will be produced at most once. If the map +is <code>nil</code>, the number of iterations is 0. </li> <li> For channels, the iteration values produced are the successive values sent on -the channel until the channel is closed -(§<a href="#Close"><code>close</code>). +the channel until the channel is <a href="#Close">closed</a>. If the channel +is <code>nil</code>, the range expression blocks forever. </li> </ol> @@ -4030,9 +4069,17 @@ after execution their values will be those of the last iteration. </p> <pre> +var testdata *struct { + a *[7]int +} +for i, _ := range testdata.a { + // testdata.a is never evaluated; len(testdata.a) is constant + // i ranges from 0 to 6 + f(i) +} + var a [10]string m := map[string]int{"mon":0, "tue":1, "wed":2, "thu":3, "fri":4, "sat":5, "sun":6} - for i, s := range a { // type of i is int // type of s is string @@ -4047,6 +4094,11 @@ for key, val = range m { } // key == last map key encountered in iteration // val == map[key] + +var ch chan Work = producer() +for w := range ch { + doWork(w) +} </pre> @@ -4131,7 +4183,7 @@ case i1 = <-c1: print("received ", i1, " from c1\n") case c2 <- i2: print("sent ", i2, " to c2\n") -case i3, ok := <-c3: +case i3, ok := (<-c3): // same as: i3, ok := <-c3 if ok { print("received ", i3, " from c3\n") } else { @@ -4229,7 +4281,7 @@ func (devnull) Write(p []byte) (n int, _ os.Error) { Regardless of how they are declared, all the result values are initialized to the zero values for their type (§<a href="#The_zero_value">The zero value</a>) upon entry to the function. </p> -<!--- +<!-- <p> <span class="alert"> TODO: Define when return is required.<br /> @@ -4237,7 +4289,7 @@ TODO: Language about result parameters needs to go into a section on function/method invocation<br /> </span> </p> ----> +--> <h3 id="Break_statements">Break statements</h3> @@ -4314,9 +4366,9 @@ L: <p> is erroneous because the jump to label <code>L</code> skips the creation of <code>v</code>. -<!--- +<!-- (<span class="alert">TODO: Eliminate in favor of used and not set errors?</span>) ----> +--> </p> <h3 id="Fallthrough_statements">Fallthrough statements</h3> @@ -4421,17 +4473,17 @@ The implementation guarantees that the result always fits into an <code>int</cod </p> <pre class="grammar"> -Call Argument type Result +Call Argument type Result -len(s) string type string length in bytes - [n]T, *[n]T array length (== n) - []T slice length - map[K]T map length (number of defined keys) - chan T number of elements queued in channel buffer +len(s) string type string length in bytes + [n]T, *[n]T array length (== n) + []T slice length + map[K]T map length (number of defined keys) + chan T number of elements queued in channel buffer -cap(s) [n]T, *[n]T array length (== n) - []T slice capacity - chan T channel buffer capacity +cap(s) [n]T, *[n]T array length (== n) + []T slice capacity + chan T channel buffer capacity </pre> <p> @@ -4449,20 +4501,17 @@ The length and capacity of a <code>nil</code> slice, map, or channel are 0. </p> <p> -The expression -<code>len(s)</code> is a -<a href="#Constants">constant</a> if <code>s</code> is a string constant. -The expressions -<code>len(s)</code> and -<code>cap(s)</code> are -constants if <code>s</code> is an (optionally parenthesized) -identifier or -<a href="#Qualified_identifiers">qualified identifier</a> -denoting an array or pointer to array. -Otherwise invocations of <code>len</code> and <code>cap</code> are not -constant. +The expression <code>len(s)</code> is <a href="#Constants">constant</a> if +<code>s</code> is a string constant. The expressions <code>len(s)</code> and +<code>cap(s)</code> are constants if the type of <code>s</code> is an array +or pointer to an array and the expression <code>s</code> does not contain +<a href="#Receive_operator">channel receives</a> or +<a href="#Calls">function calls</a>; in this case <code>s</code> is not evaluated. +Otherwise, invocations of <code>len</code> and <code>cap</code> are not +constant and <code>s</code> is evaluated. </p> + <h3 id="Allocation">Allocation</h3> <p> @@ -4575,7 +4624,7 @@ a source <code>src</code> to a destination <code>dst</code> and returns the number of elements copied. Source and destination may overlap. Both arguments must have <a href="#Type_identity">identical</a> element type <code>T</code> and must be <a href="#Assignability">assignable</a> to a slice of type <code>[]T</code>. -The number of arguments copied is the minimum of +The number of elements copied is the minimum of <code>len(src)</code> and <code>len(dst)</code>. As a special case, <code>copy</code> also accepts a destination argument assignable to type <code>[]byte</code> with a source argument of a string type. @@ -4850,7 +4899,7 @@ package main import "fmt" -// Send the sequence 2, 3, 4, ... to channel 'ch'. +// Send the sequence 2, 3, 4, … to channel 'ch'. func generate(ch chan<- int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. @@ -4890,7 +4939,7 @@ func main() { <h3 id="The_zero_value">The zero value</h3> <p> When memory is allocated to store a value, either through a declaration -or <code>make()</code> or <code>new()</code> call, +or a call of <code>make</code> or <code>new</code>, and no explicit initialization is provided, the memory is given a default initialization. Each element of such a value is set to the <i>zero value</i> for its type: <code>false</code> for booleans, @@ -4948,7 +4997,7 @@ func init() <p> defined in its source. A package may contain multiple -<code>init()</code> functions, even +<code>init</code> functions, even within a single source file; they execute in unspecified order. </p> @@ -4978,8 +5027,8 @@ program is complete. Therefore, all initialization code is run in a single goroutine. </p> <p> -An <code>init()</code> function cannot be referred to from anywhere -in a program. In particular, <code>init()</code> cannot be called explicitly, +An <code>init</code> function cannot be referred to from anywhere +in a program. In particular, <code>init</code> cannot be called explicitly, nor can a pointer to <code>init</code> be assigned to a function variable. </p> <p> @@ -5001,7 +5050,7 @@ arguments and returns no value. </p> <pre> -func main() { ... } +func main() { … } </pre> <p> @@ -5151,5 +5200,8 @@ The following minimal alignment properties are guaranteed: <h2 id="Implementation_differences"><span class="alert">Implementation differences - TODO</span></h2> <ul> - <li><span class="alert">Implementation does not honor the restriction on goto statements and targets (no intervening declarations).</span></li> + <li><span class="alert">The restriction on <code>goto</code> statements and targets (no intervening declarations) is not honored.</span></li> + <li><span class="alert"><code>len(a)</code> is only a constant if <code>a</code> is a (qualified) identifier denoting an array or pointer to an array.</span></li> + <li><span class="alert"><code>nil</code> maps are not treated like empty maps.</span></li> + <li><span class="alert">Trying to send/receive from a <code>nil</code> channel causes a run-time panic.</span></li> </ul> diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index 4470f2748..aa85134b3 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -28,9 +28,9 @@ Let's start in the usual way: <p> <pre> <!-- progs/helloworld.go /package/ END --> 05 package main -<p> + 07 import fmt "fmt" // Package implementing formatted I/O. -<p> + 09 func main() { 10 fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n") 11 } @@ -118,19 +118,19 @@ Next up, here's a version of the Unix utility <code>echo(1)</code>: <p> <pre> <!-- progs/echo.go /package/ END --> 05 package main -<p> + 07 import ( 08 "os" 09 "flag" // command line option parser 10 ) -<p> + 12 var omitNewline = flag.Bool("n", false, "don't print final newline") -<p> + 14 const ( 15 Space = " " 16 Newline = "\n" 17 ) -<p> + 19 func main() { 20 flag.Parse() // Scans the arg list and sets up flags 21 var s string = "" @@ -340,7 +340,7 @@ Using slices one can write this function (from <code>sum.go</code>): 15 } </pre> <p> -Note how the return type (<code>int</code>) is defined for <code>sum()</code> by stating it +Note how the return type (<code>int</code>) is defined for <code>sum</code> by stating it after the parameter list. <p> To call the function, we slice the array. This intricate call (we'll show @@ -372,7 +372,7 @@ There are also maps, which you can initialize like this: m := map[string]int{"one":1 , "two":2} </pre> <p> -The built-in function <code>len()</code>, which returns number of elements, +The built-in function <code>len</code>, which returns number of elements, makes its first appearance in <code>sum</code>. It works on strings, arrays, slices, maps, and channels. <p> @@ -400,7 +400,7 @@ for more examples of its use. Most types in Go are values. If you have an <code>int</code> or a <code>struct</code> or an array, assignment copies the contents of the object. -To allocate a new variable, use <code>new()</code>, which +To allocate a new variable, use the built-in function <code>new</code>, which returns a pointer to the allocated storage. <p> <pre> @@ -417,7 +417,7 @@ or the more idiomatic Some types—maps, slices, and channels (see below)—have reference semantics. If you're holding a slice or a map and you modify its contents, other variables referencing the same underlying data will see the modification. For these three -types you want to use the built-in function <code>make()</code>: +types you want to use the built-in function <code>make</code>: <p> <pre> m := make(map[string]int) @@ -431,11 +431,11 @@ If you just declare the map, as in </pre> <p> it creates a <code>nil</code> reference that cannot hold anything. To use the map, -you must first initialize the reference using <code>make()</code> or by assignment from an +you must first initialize the reference using <code>make</code> or by assignment from an existing map. <p> Note that <code>new(T)</code> returns type <code>*T</code> while <code>make(T)</code> returns type -<code>T</code>. If you (mistakenly) allocate a reference object with <code>new()</code>, +<code>T</code>. If you (mistakenly) allocate a reference object with <code>new</code> rather than <code>make</code>, you receive a pointer to a nil reference, equivalent to declaring an uninitialized variable and taking its address. <p> @@ -478,12 +478,12 @@ open/close/read/write interface. Here's the start of <code>file.go</code>: <p> <pre> <!-- progs/file.go /package/ /^}/ --> 05 package file -<p> + 07 import ( 08 "os" 09 "syscall" 10 ) -<p> + 12 type File struct { 13 fd int // file descriptor number 14 name string // file name at Open time @@ -600,7 +600,7 @@ the tricky standard arguments to open and, especially, to create a file: 41 O_CREATE = syscall.O_CREAT 42 O_TRUNC = syscall.O_TRUNC 43 ) -<p> + 45 func Open(name string) (file *File, err os.Error) { 46 return OpenFile(name, O_RDONLY, 0) 47 } @@ -631,7 +631,7 @@ each of which declares a receiver variable <code>file</code>. 61 } 62 return nil 63 } -<p> + 65 func (file *File) Read(b []byte) (ret int, err os.Error) { 66 if file == nil { 67 return -1, os.EINVAL @@ -642,7 +642,7 @@ each of which declares a receiver variable <code>file</code>. 72 } 73 return int(r), err 74 } -<p> + 76 func (file *File) Write(b []byte) (ret int, err os.Error) { 77 if file == nil { 78 return -1, os.EINVAL @@ -653,7 +653,7 @@ each of which declares a receiver variable <code>file</code>. 83 } 84 return int(r), err 85 } -<p> + 87 func (file *File) String() string { 88 return file.name 89 } @@ -676,13 +676,13 @@ We can now use our new package: <p> <pre> <!-- progs/helloworld3.go /package/ END --> 05 package main -<p> + 07 import ( 08 "./file" 09 "fmt" 10 "os" 11 ) -<p> + 13 func main() { 14 hello := []byte("hello, world\n") 15 file.Stdout.Write(hello) @@ -719,14 +719,14 @@ Building on the <code>file</code> package, here's a simple version of the Unix u <p> <pre> <!-- progs/cat.go /package/ END --> 05 package main -<p> + 07 import ( 08 "./file" 09 "flag" 10 "fmt" 11 "os" 12 ) -<p> + 14 func cat(f *file.File) { 15 const NBUF = 512 16 var buf [NBUF]byte @@ -745,7 +745,7 @@ Building on the <code>file</code> package, here's a simple version of the Unix u 29 } 30 } 31 } -<p> + 33 func main() { 34 flag.Parse() // Scans the arg list and sets up flags 35 if flag.NArg() == 0 { @@ -766,7 +766,7 @@ Building on the <code>file</code> package, here's a simple version of the Unix u By now this should be easy to follow, but the <code>switch</code> statement introduces some new features. Like a <code>for</code> loop, an <code>if</code> or <code>switch</code> can include an initialization statement. The <code>switch</code> on line 18 uses one to create variables -<code>nr</code> and <code>er</code> to hold the return values from <code>f.Read()</code>. (The <code>if</code> on line 25 +<code>nr</code> and <code>er</code> to hold the return values from the call to <code>f.Read</code>. (The <code>if</code> on line 25 has the same idea.) The <code>switch</code> statement is general: it evaluates the cases from top to bottom looking for the first case that matches the value; the case expressions don't need to be constants or even integers, as long as @@ -778,14 +778,14 @@ in a <code>for</code> statement, a missing value means <code>true</code>. In fa is a form of <code>if-else</code> chain. While we're here, it should be mentioned that in <code>switch</code> statements each <code>case</code> has an implicit <code>break</code>. <p> -Line 25 calls <code>Write()</code> by slicing the incoming buffer, which is itself a slice. +Line 25 calls <code>Write</code> by slicing the incoming buffer, which is itself a slice. Slices provide the standard Go way to handle I/O buffers. <p> Now let's make a variant of <code>cat</code> that optionally does <code>rot13</code> on its input. It's easy to do by just processing the bytes, but instead we will exploit Go's notion of an <i>interface</i>. <p> -The <code>cat()</code> subroutine uses only two methods of <code>f</code>: <code>Read()</code> and <code>String()</code>, +The <code>cat</code> subroutine uses only two methods of <code>f</code>: <code>Read</code> and <code>String</code>, so let's start by defining an interface that has exactly those two methods. Here is code from <code>progs/cat_rot13.go</code>: <p> @@ -810,11 +810,11 @@ we have a second implementation of the <code>reader</code> interface. 31 type rotate13 struct { 32 source reader 33 } -<p> + 35 func newRotate13(source reader) *rotate13 { 36 return &rotate13{source} 37 } -<p> + 39 func (r13 *rotate13) Read(b []byte) (ret int, err os.Error) { 40 r, e := r13.source.Read(b) 41 for i := 0; i < r; i++ { @@ -822,7 +822,7 @@ we have a second implementation of the <code>reader</code> interface. 43 } 44 return r, e 45 } -<p> + 47 func (r13 *rotate13) String() string { 48 return r13.source.String() 49 } @@ -837,13 +837,13 @@ To use the new feature, we define a flag: 14 var rot13Flag = flag.Bool("rot13", false, "rot13 the input") </pre> <p> -and use it from within a mostly unchanged <code>cat()</code> function: +and use it from within a mostly unchanged <code>cat</code> function: <p> <pre> <!-- progs/cat_rot13.go /func.cat/ /^}/ --> 52 func cat(r reader) { 53 const NBUF = 512 54 var buf [NBUF]byte -<p> + 56 if *rot13Flag { 57 r = newRotate13(r) 58 } @@ -865,7 +865,7 @@ and use it from within a mostly unchanged <code>cat()</code> function: 74 } </pre> <p> -(We could also do the wrapping in <code>main</code> and leave <code>cat()</code> mostly alone, except +(We could also do the wrapping in <code>main</code> and leave <code>cat</code> mostly alone, except for changing the type of the argument; consider that an exercise.) Lines 56 through 58 set it all up: If the <code>rot13</code> flag is true, wrap the <code>reader</code> we received into a <code>rotate13</code> and proceed. Note that the interface variables @@ -936,7 +936,7 @@ arrays of integers, strings, etc.; here's the code for arrays of <code>int</code <p> <pre> <!-- progs/sort.go /type.*IntArray/ /Swap/ --> 33 type IntArray []int -<p> + 35 func (p IntArray) Len() int { return len(p) } 36 func (p IntArray) Less(i, j int) bool { return p[i] < p[j] } 37 func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i] } @@ -969,11 +969,11 @@ to implement the three methods for that type, like this: 32 shortName string 33 longName string 34 } -<p> + 36 type dayArray struct { 37 data []*day 38 } -<p> + 40 func (p *dayArray) Len() int { return len(p.data) } 41 func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num } 42 func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i] } @@ -1054,7 +1054,7 @@ to that of the <code>Printf</code> call above. </pre> <p> If you have your own type you'd like <code>Printf</code> or <code>Print</code> to format, -just give it a <code>String()</code> method that returns a string. The print +just give it a <code>String</code> method that returns a string. The print routines will examine the value to inquire whether it implements the method and if so, use it rather than some other formatting. Here's a simple example. @@ -1064,25 +1064,25 @@ Here's a simple example. 10 a int 11 b string 12 } -<p> + 14 func (t *testType) String() string { 15 return fmt.Sprint(t.a) + " " + t.b 16 } -<p> + 18 func main() { 19 t := &testType{77, "Sunset Strip"} 20 fmt.Println(t) 21 } </pre> <p> -Since <code>*testType</code> has a <code>String()</code> method, the +Since <code>*testType</code> has a <code>String</code> method, the default formatter for that type will use it and produce the output <p> <pre> 77 Sunset Strip </pre> <p> -Observe that the <code>String()</code> method calls <code>Sprint</code> (the obvious Go +Observe that the <code>String</code> method calls <code>Sprint</code> (the obvious Go variant that returns a string) to do its formatting; special formatters can use the <code>fmt</code> library recursively. <p> @@ -1095,7 +1095,7 @@ and such, but that's getting a little off the main thread so we'll leave it as an exploration exercise. <p> You might ask, though, how <code>Printf</code> can tell whether a type implements -the <code>String()</code> method. Actually what it does is ask if the value can +the <code>String</code> method. Actually what it does is ask if the value can be converted to an interface variable that implements the method. Schematically, given a value <code>v</code>, it does this: <p> @@ -1140,7 +1140,7 @@ interface type defined in the <code>io</code> library: <p> (This interface is another conventional name, this time for <code>Write</code>; there are also <code>io.Reader</code>, <code>io.ReadWriter</code>, and so on.) -Thus you can call <code>Fprintf</code> on any type that implements a standard <code>Write()</code> +Thus you can call <code>Fprintf</code> on any type that implements a standard <code>Write</code> method, not just files but also network channels, buffers, whatever you want. <p> @@ -1346,7 +1346,7 @@ code that invokes the operation and responds to the request: <p> <pre> <!-- progs/server.go /type.binOp/ /^}/ --> 14 type binOp func(a, b int) int -<p> + 16 func run(op binOp, req *request) { 17 reply := op(req.a, req.b) 18 req.replyc <- reply diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt index 3e0b21d99..513190ef2 100644 --- a/doc/go_tutorial.txt +++ b/doc/go_tutorial.txt @@ -271,7 +271,7 @@ Using slices one can write this function (from "sum.go"): --PROG progs/sum.go /sum/ /^}/ -Note how the return type ("int") is defined for "sum()" by stating it +Note how the return type ("int") is defined for "sum" by stating it after the parameter list. To call the function, we slice the array. This intricate call (we'll show @@ -295,7 +295,7 @@ There are also maps, which you can initialize like this: m := map[string]int{"one":1 , "two":2} -The built-in function "len()", which returns number of elements, +The built-in function "len", which returns number of elements, makes its first appearance in "sum". It works on strings, arrays, slices, maps, and channels. @@ -320,7 +320,7 @@ An Interlude about Allocation Most types in Go are values. If you have an "int" or a "struct" or an array, assignment copies the contents of the object. -To allocate a new variable, use "new()", which +To allocate a new variable, use the built-in function "new", which returns a pointer to the allocated storage. type T struct { a, b int } @@ -333,7 +333,7 @@ or the more idiomatic Some types—maps, slices, and channels (see below)—have reference semantics. If you're holding a slice or a map and you modify its contents, other variables referencing the same underlying data will see the modification. For these three -types you want to use the built-in function "make()": +types you want to use the built-in function "make": m := make(map[string]int) @@ -343,11 +343,11 @@ If you just declare the map, as in var m map[string]int it creates a "nil" reference that cannot hold anything. To use the map, -you must first initialize the reference using "make()" or by assignment from an +you must first initialize the reference using "make" or by assignment from an existing map. Note that "new(T)" returns type "*T" while "make(T)" returns type -"T". If you (mistakenly) allocate a reference object with "new()", +"T". If you (mistakenly) allocate a reference object with "new" rather than "make", you receive a pointer to a nil reference, equivalent to declaring an uninitialized variable and taking its address. @@ -525,7 +525,7 @@ Building on the "file" package, here's a simple version of the Unix utility "cat By now this should be easy to follow, but the "switch" statement introduces some new features. Like a "for" loop, an "if" or "switch" can include an initialization statement. The "switch" on line 18 uses one to create variables -"nr" and "er" to hold the return values from "f.Read()". (The "if" on line 25 +"nr" and "er" to hold the return values from the call to "f.Read". (The "if" on line 25 has the same idea.) The "switch" statement is general: it evaluates the cases from top to bottom looking for the first case that matches the value; the case expressions don't need to be constants or even integers, as long as @@ -537,14 +537,14 @@ in a "for" statement, a missing value means "true". In fact, such a "switch" is a form of "if-else" chain. While we're here, it should be mentioned that in "switch" statements each "case" has an implicit "break". -Line 25 calls "Write()" by slicing the incoming buffer, which is itself a slice. +Line 25 calls "Write" by slicing the incoming buffer, which is itself a slice. Slices provide the standard Go way to handle I/O buffers. Now let's make a variant of "cat" that optionally does "rot13" on its input. It's easy to do by just processing the bytes, but instead we will exploit Go's notion of an <i>interface</i>. -The "cat()" subroutine uses only two methods of "f": "Read()" and "String()", +The "cat" subroutine uses only two methods of "f": "Read" and "String", so let's start by defining an interface that has exactly those two methods. Here is code from "progs/cat_rot13.go": @@ -568,11 +568,11 @@ To use the new feature, we define a flag: --PROG progs/cat_rot13.go /rot13Flag/ -and use it from within a mostly unchanged "cat()" function: +and use it from within a mostly unchanged "cat" function: --PROG progs/cat_rot13.go /func.cat/ /^}/ -(We could also do the wrapping in "main" and leave "cat()" mostly alone, except +(We could also do the wrapping in "main" and leave "cat" mostly alone, except for changing the type of the argument; consider that an exercise.) Lines 56 through 58 set it all up: If the "rot13" flag is true, wrap the "reader" we received into a "rotate13" and proceed. Note that the interface variables @@ -700,19 +700,19 @@ to that of the "Printf" call above. --PROG progs/print.go 'NR==21' 'NR==22' If you have your own type you'd like "Printf" or "Print" to format, -just give it a "String()" method that returns a string. The print +just give it a "String" method that returns a string. The print routines will examine the value to inquire whether it implements the method and if so, use it rather than some other formatting. Here's a simple example. --PROG progs/print_string.go 'NR==9' END -Since "*testType" has a "String()" method, the +Since "*testType" has a "String" method, the default formatter for that type will use it and produce the output 77 Sunset Strip -Observe that the "String()" method calls "Sprint" (the obvious Go +Observe that the "String" method calls "Sprint" (the obvious Go variant that returns a string) to do its formatting; special formatters can use the "fmt" library recursively. @@ -725,7 +725,7 @@ and such, but that's getting a little off the main thread so we'll leave it as an exploration exercise. You might ask, though, how "Printf" can tell whether a type implements -the "String()" method. Actually what it does is ask if the value can +the "String" method. Actually what it does is ask if the value can be converted to an interface variable that implements the method. Schematically, given a value "v", it does this: @@ -764,7 +764,7 @@ interface type defined in the "io" library: (This interface is another conventional name, this time for "Write"; there are also "io.Reader", "io.ReadWriter", and so on.) -Thus you can call "Fprintf" on any type that implements a standard "Write()" +Thus you can call "Fprintf" on any type that implements a standard "Write" method, not just files but also network channels, buffers, whatever you want. diff --git a/doc/godocs.js b/doc/godocs.js index 2b3ab065f..946c4c39f 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -28,6 +28,10 @@ function godocs_onload() { function godocs_bindSearchEvents() { var search = document.getElementById('search'); + if (!search) { + // no search box (index disabled) + return; + } function clearInactive() { if (search.className == "inactive") { search.value = ""; @@ -100,7 +104,7 @@ function godocs_generateTOC() { } } - if (!toc_items.length) { return; } + if (toc_items.length <= 1) { return; } var dl1 = document.createElement('dl'); var dl2 = document.createElement('dl'); diff --git a/doc/htmlgen.go b/doc/htmlgen.go index 4d68767c3..3a8feb8bc 100644 --- a/doc/htmlgen.go +++ b/doc/htmlgen.go @@ -5,7 +5,7 @@ // Process plain text into HTML. // - h2's are made from lines followed by a line "----\n" // - tab-indented blocks become <pre> blocks -// - blank lines become <p> marks +// - blank lines become <p> marks (except inside <pre> tags) // - "quoted strings" become <code>quoted strings</code> package main @@ -35,9 +35,9 @@ var ( func main() { read() headings() - paragraphs() coalesce(preStart, foldPre) coalesce(tab, foldTabs) + paragraphs() quotes() write() } diff --git a/doc/root.html b/doc/root.html index f98f9c243..8d76928c8 100644 --- a/doc/root.html +++ b/doc/root.html @@ -60,7 +60,7 @@ google.setOnLoadCallback(loadFeed); <div id="content-rotating"> <div id="content-videos"> <h2>Go Videos <span class="more">| <a href="/doc/docs.html#videos_talks">More...</a></span></h2> - <a class="video" href="http://osdc.blip.tv/file/4432146/"><img src="/doc/play_overlay.png" class="thumbnail _004" /> <span class="caption title">“Practical Go Programming”</span> <span class="caption description">OSDC Tech Talk</span></a> + <a class="video" href="http://www.youtube.com/watch?v=-i0hat7pdpk"><img src="/doc/play_overlay.png" class="thumbnail _005" /> <span class="caption title">“Writing Web Apps in Go”</span> <span class="caption description">Google I/O 2011</span></a> </div> <h2>Go Blog <span class="more">| <a href="http://blog.golang.org/">More...</a></span></h2> <div id="content-blog"> @@ -78,9 +78,10 @@ google.setOnLoadCallback(loadFeed); <li><a href="/doc/effective_go.html">Effective Go</a></li> <li><a href="/doc/go_faq.html">Go FAQ</a></li> <li><a href="/doc/docs.html">Other Documentation</a></li> + <li><a href="http://code.google.com/appengine/docs/go/">Go for Google App Engine</a> <sup class="new">New!</sup></li> </ul> </div> - <div id="resources-contributors" class="resources"> + <div id="resources-contributors" > <h3>For developers:</h3> <ul> <li><a href="http://godashboard.appspot.com/package">Package Dashboard</a></li> diff --git a/doc/talks/io2011/Real_World_Go.pdf b/doc/talks/io2011/Real_World_Go.pdf Binary files differnew file mode 100644 index 000000000..2a187116b --- /dev/null +++ b/doc/talks/io2011/Real_World_Go.pdf diff --git a/doc/talks/io2011/Writing_Web_Apps_in_Go.pdf b/doc/talks/io2011/Writing_Web_Apps_in_Go.pdf Binary files differnew file mode 100644 index 000000000..ca4702ee9 --- /dev/null +++ b/doc/talks/io2011/Writing_Web_Apps_in_Go.pdf diff --git a/doc/video-005.jpg b/doc/video-005.jpg Binary files differnew file mode 100644 index 000000000..32371581f --- /dev/null +++ b/doc/video-005.jpg |