From 77f6f16660099e09f4707e0ace53fb26d9a024b9 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 25 Dec 2009 07:13:14 +1100 Subject: [PATCH] fix naked < and > as reported by Peter Williams <> (i thought these were legal in
 blocks)

R=rsc
CC=golang-dev, pwil3058
https://golang.org/cl/181055
---
 doc/effective_go.html | 80 +++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/doc/effective_go.html b/doc/effective_go.html
index c9f1a125755..29327095023 100644
--- a/doc/effective_go.html
+++ b/doc/effective_go.html
@@ -405,7 +405,7 @@ effects.  Write them like this
 

-if i < f() {
+if i < f() {
     g()
 }
 
@@ -413,7 +413,7 @@ if i < f() { not like this

-if i < f()  // wrong!
+if i < f()  // wrong!
 {           // wrong!
     g()
 }
@@ -444,7 +444,7 @@ and the bodies must always be brace-delimited.
 In Go a simple if looks like this:
 

-if x > 0 {
+if x > 0 {
     return y
 }
 
@@ -529,7 +529,7 @@ Short declarations make it easy to declare the index variable right in the loop.

 sum := 0
-for i := 0; i < 10; i++ {
+for i := 0; i < 10; i++ {
     sum += i
 }
 
@@ -573,7 +573,7 @@ you should use parallel assignment.

 // Reverse a
-for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
+for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
     a[i], a[j] = a[j], a[i]
 }
 
@@ -708,10 +708,10 @@ and the next position.
 func nextInt(b []byte, i int) (int, int) {
-    for ; i < len(b) && !isDigit(b[i]); i++ {
+    for ; i < len(b) && !isDigit(b[i]); i++ {
     }
     x := 0
-    for ; i < len(b) && isDigit(b[i]); i++ {
+    for ; i < len(b) && isDigit(b[i]); i++ {
         x = x*10 + int(b[i])-'0'
     }
     return x, i
@@ -723,7 +723,7 @@ You could use it to scan the numbers in an input array a like this:
 

-    for i := 0; i < len(a); {
+    for i := 0; i < len(a); {
         x, i = nextInt(a, i)
         fmt.Println(x)
     }
@@ -760,7 +760,7 @@ of io.ReadFull that uses them well:
 
 
 func ReadFull(r Reader, buf []byte) (n int, err os.Error) {
-    for len(buf) > 0 && err == nil {
+    for len(buf) > 0 && err == nil {
         var nr int
         nr, err = r.Read(buf)
         n += nr
@@ -1044,7 +1044,7 @@ the moment, this snippet would also read the first 32 bytes of the buffer.
 
     var n int
     var err os.Error
-    for i := 0; i < 32; i++ {
+    for i := 0; i < 32; i++ {
         nbytes, e := f.Read(buf[i:i+1])  // Read one byte.
         if nbytes == 0 || e != nil {
             err = e
@@ -1067,7 +1067,7 @@ resulting slice is returned.  The function uses the fact that
 
 func Append(slice, data[]byte) []byte {
     l := len(slice)
-    if l + len(data) > cap(slice) {  // reallocate
+    if l + len(data) > cap(slice) {  // reallocate
         // Allocate double what's needed, for future growth.
         newSlice := make([]byte, (l+len(data))*2)
         // Copy data (could use bytes.Copy()).
@@ -1202,7 +1202,7 @@ do not take flags for signedness or size; instead, the printing routines use the
 type of the argument to decide these properties.
 

-var x uint64 = 1<<64 - 1
+var x uint64 = 1<<64 - 1
 fmt.Printf("%d %x; %d %x\n", x, x, int64(x), int64(x))
 

@@ -1355,7 +1355,7 @@ sets of values. type ByteSize float64 const ( _ = iota // ignore first value by assigning to blank identifier - KB ByteSize = 1<<(10*iota) + KB ByteSize = 1<<(10*iota) MB GB TB @@ -1371,17 +1371,17 @@ automatically for printing, even as part of a general type.

 func (b ByteSize) String() string {
     switch {
-    case b >= YB:
+    case b >= YB:
         return fmt.Sprintf("%.2fYB", b/YB)
-    case b >= PB:
+    case b >= PB:
         return fmt.Sprintf("%.2fPB", b/PB)
-    case b >= TB:
+    case b >= TB:
         return fmt.Sprintf("%.2fTB", b/TB)
-    case b >= GB:
+    case b >= GB:
         return fmt.Sprintf("%.2fGB", b/GB)
-    case b >= MB:
+    case b >= MB:
         return fmt.Sprintf("%.2fMB", b/MB)
-    case b >= KB:
+    case b >= KB:
         return fmt.Sprintf("%.2fKB", b/KB)
     }
     return fmt.Sprintf("%.2fB", b)
@@ -1539,7 +1539,7 @@ func (s Sequence) Len() int {
     return len(s)
 }
 func (s Sequence) Less(i, j int) bool {
-    return s[i] < s[j]
+    return s[i] < s[j]
 }
 func (s Sequence) Swap(i, j int) {
     s[i], s[j] = s[j], s[i]
@@ -1550,7 +1550,7 @@ func (s Sequence) String() string {
     sort.Sort(s)
     str := "["
     for i, elem := range s {
-        if i > 0 {
+        if i > 0 {
             str += " "
         }
         str += fmt.Sprint(elem)
@@ -1733,7 +1733,7 @@ has been visited?  Tie a channel to the web page.
 type Chan chan *http.Request
 
 func (ch Chan) ServeHTTP(c *http.Conn, req *http.Request) {
-    ch <- req
+    ch <- req
     fmt.Fprint(c, "notification sent")
 }
 
@@ -2110,14 +2110,14 @@ simultaneous calls to process. var sem = make(chan int, MaxOutstanding) func handle(r *Request) { - sem <- 1 // Wait for active queue to drain. + sem <- 1 // Wait for active queue to drain. process(r) // May take a long time. - <-sem // Done; enable next request to run. + <-sem // Done; enable next request to run. } func Serve(queue chan *Request) { for { - req := <-queue + req := <-queue go handle(req) // Don't wait for handle to finish. } } @@ -2141,10 +2141,10 @@ func handle(queue chan *Request) { func Serve(clientRequests chan *clientRequests, quit chan bool) { // Start handlers - for i := 0; i < MaxOutstanding; i++ { + for i := 0; i < MaxOutstanding; i++ { go handle(clientRequests) } - <-quit // Wait to be told to exit. + <-quit // Wait to be told to exit. }
@@ -2182,9 +2182,9 @@ func sum(a []int) (s int) { request := &Request{[]int{3, 4, 5}, sum, make(chan int)} // Send request -clientRequests <- request +clientRequests <- request // Wait for response. -fmt.Printf("answer: %d\n", <-request.resultChan) +fmt.Printf("answer: %d\n", <-request.resultChan)

On the server side, the handler function is the only thing that changes. @@ -2192,7 +2192,7 @@ On the server side, the handler function is the only thing that changes.

 func handle(queue chan *Request) {
     for req := range queue {
-        req.resultChan <- req.f(req.args)
+        req.resultChan <- req.f(req.args)
     }
 }
 
@@ -2219,10 +2219,10 @@ type Vector []float64 // Apply the operation to v[i], v[i+1] ... up to v[n-1]. func (v Vector) DoSome(i, n int, u Vector, c chan int) { - for ; i < n; i++ { + for ; i < n; i++ { v[i] += u.Op(v[i]) } - c <- 1 // signal that this piece is done + c <- 1 // signal that this piece is done }

@@ -2236,12 +2236,12 @@ const NCPU = 4 // number of CPU cores func (v Vector) DoAll(u Vector) { c := make(chan int, NCPU) // Buffering optional but sensible. - for i := 0; i < NCPU; i++ { + for i := 0; i < NCPU; i++ { go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c) } // Drain the channel. - for i := 0; i < NCPU; i++ { - <-c // wait for one task to complete + for i := 0; i < NCPU; i++ { + <-c // wait for one task to complete } // All done. } @@ -2282,12 +2282,12 @@ var serverChan = make(chan *Buffer) func client() { for { - b, ok := <-freeList // grab a buffer if available + b, ok := <-freeList // grab a buffer if available if !ok { // if not, allocate a new one b = new(Buffer) } load(b) // read next message from the net - serverChan <- b // send to server + serverChan <- b // send to server } }

@@ -2298,9 +2298,9 @@ and returns the buffer to the free list.
 func server() {
     for {
-        b := <-serverChan    // wait for work
+        b := <-serverChan    // wait for work
         process(b)
-        _ = freeList <- b    // reuse buffer if room
+        _ = freeList <- b    // reuse buffer if room
     }
 }
 
@@ -2377,7 +2377,7 @@ field for recoverable failures.

-for try := 0; try < 2; try++ {
+for try := 0; try < 2; try++ {
     file, err = os.Open(filename, os.O_RDONLY, 0)
     if err == nil {
         return