1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:34:39 -07:00

fix naked < and > as reported by Peter Williams <>

(i thought these were legal in <pre> blocks)

R=rsc
CC=golang-dev, pwil3058
https://golang.org/cl/181055
This commit is contained in:
Rob Pike 2009-12-25 07:13:14 +11:00
parent 2be4897800
commit 77f6f16660

View File

@ -405,7 +405,7 @@ effects. Write them like this
</p> </p>
<pre> <pre>
if i < f() { if i &lt; f() {
g() g()
} }
</pre> </pre>
@ -413,7 +413,7 @@ if i < f() {
not like this not like this
</p> </p>
<pre> <pre>
if i < f() // wrong! if i &lt; f() // wrong!
{ // wrong! { // wrong!
g() g()
} }
@ -444,7 +444,7 @@ and the bodies must always be brace-delimited.
In Go a simple <code>if</code> looks like this: In Go a simple <code>if</code> looks like this:
</p> </p>
<pre> <pre>
if x > 0 { if x &gt; 0 {
return y return y
} }
</pre> </pre>
@ -529,7 +529,7 @@ Short declarations make it easy to declare the index variable right in the loop.
</p> </p>
<pre> <pre>
sum := 0 sum := 0
for i := 0; i < 10; i++ { for i := 0; i &lt; 10; i++ {
sum += i sum += i
} }
</pre> </pre>
@ -573,7 +573,7 @@ you should use parallel assignment.
</p> </p>
<pre> <pre>
// Reverse a // 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 &lt; j; i, j = i+1, j-1 {
a[i], a[j] = a[j], a[i] a[i], a[j] = a[j], a[i]
} }
</pre> </pre>
@ -708,10 +708,10 @@ and the next position.
<pre> <pre>
func nextInt(b []byte, i int) (int, int) { func nextInt(b []byte, i int) (int, int) {
for ; i < len(b) &amp;&amp; !isDigit(b[i]); i++ { for ; i &lt; len(b) &amp;&amp; !isDigit(b[i]); i++ {
} }
x := 0 x := 0
for ; i < len(b) &amp;&amp; isDigit(b[i]); i++ { for ; i &lt; len(b) &amp;&amp; isDigit(b[i]); i++ {
x = x*10 + int(b[i])-'0' x = x*10 + int(b[i])-'0'
} }
return x, i return x, i
@ -723,7 +723,7 @@ You could use it to scan the numbers in an input array <code>a</code> like this:
</p> </p>
<pre> <pre>
for i := 0; i < len(a); { for i := 0; i &lt; len(a); {
x, i = nextInt(a, i) x, i = nextInt(a, i)
fmt.Println(x) fmt.Println(x)
} }
@ -760,7 +760,7 @@ of <code>io.ReadFull</code> that uses them well:
<pre> <pre>
func ReadFull(r Reader, buf []byte) (n int, err os.Error) { func ReadFull(r Reader, buf []byte) (n int, err os.Error) {
for len(buf) > 0 &amp;&amp; err == nil { for len(buf) &gt; 0 &amp;&amp; err == nil {
var nr int var nr int
nr, err = r.Read(buf) nr, err = r.Read(buf)
n += nr n += nr
@ -1044,7 +1044,7 @@ the moment, this snippet would also read the first 32 bytes of the buffer.
<pre> <pre>
var n int var n int
var err os.Error var err os.Error
for i := 0; i < 32; i++ { for i := 0; i &lt; 32; i++ {
nbytes, e := f.Read(buf[i:i+1]) // Read one byte. nbytes, e := f.Read(buf[i:i+1]) // Read one byte.
if nbytes == 0 || e != nil { if nbytes == 0 || e != nil {
err = e err = e
@ -1067,7 +1067,7 @@ resulting slice is returned. The function uses the fact that
<pre> <pre>
func Append(slice, data[]byte) []byte { func Append(slice, data[]byte) []byte {
l := len(slice) l := len(slice)
if l + len(data) > cap(slice) { // reallocate if l + len(data) &gt; cap(slice) { // reallocate
// Allocate double what's needed, for future growth. // Allocate double what's needed, for future growth.
newSlice := make([]byte, (l+len(data))*2) newSlice := make([]byte, (l+len(data))*2)
// Copy data (could use bytes.Copy()). // 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. type of the argument to decide these properties.
</p> </p>
<pre> <pre>
var x uint64 = 1<<64 - 1 var x uint64 = 1&lt;&lt;64 - 1
fmt.Printf("%d %x; %d %x\n", x, x, int64(x), int64(x)) fmt.Printf("%d %x; %d %x\n", x, x, int64(x), int64(x))
</pre> </pre>
<p> <p>
@ -1355,7 +1355,7 @@ sets of values.
type ByteSize float64 type ByteSize float64
const ( const (
_ = iota // ignore first value by assigning to blank identifier _ = iota // ignore first value by assigning to blank identifier
KB ByteSize = 1<<(10*iota) KB ByteSize = 1&lt;&lt;(10*iota)
MB MB
GB GB
TB TB
@ -1371,17 +1371,17 @@ automatically for printing, even as part of a general type.
<pre> <pre>
func (b ByteSize) String() string { func (b ByteSize) String() string {
switch { switch {
case b >= YB: case b &gt;= YB:
return fmt.Sprintf("%.2fYB", b/YB) return fmt.Sprintf("%.2fYB", b/YB)
case b >= PB: case b &gt;= PB:
return fmt.Sprintf("%.2fPB", b/PB) return fmt.Sprintf("%.2fPB", b/PB)
case b >= TB: case b &gt;= TB:
return fmt.Sprintf("%.2fTB", b/TB) return fmt.Sprintf("%.2fTB", b/TB)
case b >= GB: case b &gt;= GB:
return fmt.Sprintf("%.2fGB", b/GB) return fmt.Sprintf("%.2fGB", b/GB)
case b >= MB: case b &gt;= MB:
return fmt.Sprintf("%.2fMB", b/MB) return fmt.Sprintf("%.2fMB", b/MB)
case b >= KB: case b &gt;= KB:
return fmt.Sprintf("%.2fKB", b/KB) return fmt.Sprintf("%.2fKB", b/KB)
} }
return fmt.Sprintf("%.2fB", b) return fmt.Sprintf("%.2fB", b)
@ -1539,7 +1539,7 @@ func (s Sequence) Len() int {
return len(s) return len(s)
} }
func (s Sequence) Less(i, j int) bool { func (s Sequence) Less(i, j int) bool {
return s[i] < s[j] return s[i] &lt; s[j]
} }
func (s Sequence) Swap(i, j int) { func (s Sequence) Swap(i, j int) {
s[i], s[j] = s[j], s[i] s[i], s[j] = s[j], s[i]
@ -1550,7 +1550,7 @@ func (s Sequence) String() string {
sort.Sort(s) sort.Sort(s)
str := "[" str := "["
for i, elem := range s { for i, elem := range s {
if i > 0 { if i &gt; 0 {
str += " " str += " "
} }
str += fmt.Sprint(elem) str += fmt.Sprint(elem)
@ -1733,7 +1733,7 @@ has been visited? Tie a channel to the web page.
type Chan chan *http.Request type Chan chan *http.Request
func (ch Chan) ServeHTTP(c *http.Conn, req *http.Request) { func (ch Chan) ServeHTTP(c *http.Conn, req *http.Request) {
ch <- req ch &lt;- req
fmt.Fprint(c, "notification sent") fmt.Fprint(c, "notification sent")
} }
</pre> </pre>
@ -2110,14 +2110,14 @@ simultaneous calls to <code>process</code>.
var sem = make(chan int, MaxOutstanding) var sem = make(chan int, MaxOutstanding)
func handle(r *Request) { func handle(r *Request) {
sem <- 1 // Wait for active queue to drain. sem &lt;- 1 // Wait for active queue to drain.
process(r) // May take a long time. process(r) // May take a long time.
<-sem // Done; enable next request to run. &lt;-sem // Done; enable next request to run.
} }
func Serve(queue chan *Request) { func Serve(queue chan *Request) {
for { for {
req := <-queue req := &lt;-queue
go handle(req) // Don't wait for handle to finish. 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) { func Serve(clientRequests chan *clientRequests, quit chan bool) {
// Start handlers // Start handlers
for i := 0; i < MaxOutstanding; i++ { for i := 0; i &lt; MaxOutstanding; i++ {
go handle(clientRequests) go handle(clientRequests)
} }
<-quit // Wait to be told to exit. &lt;-quit // Wait to be told to exit.
} }
</pre> </pre>
@ -2182,9 +2182,9 @@ func sum(a []int) (s int) {
request := &amp;Request{[]int{3, 4, 5}, sum, make(chan int)} request := &amp;Request{[]int{3, 4, 5}, sum, make(chan int)}
// Send request // Send request
clientRequests <- request clientRequests &lt;- request
// Wait for response. // Wait for response.
fmt.Printf("answer: %d\n", <-request.resultChan) fmt.Printf("answer: %d\n", &lt;-request.resultChan)
</pre> </pre>
<p> <p>
On the server side, the handler function is the only thing that changes. 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.
<pre> <pre>
func handle(queue chan *Request) { func handle(queue chan *Request) {
for req := range queue { for req := range queue {
req.resultChan <- req.f(req.args) req.resultChan &lt;- req.f(req.args)
} }
} }
</pre> </pre>
@ -2219,10 +2219,10 @@ type Vector []float64
// Apply the operation to v[i], v[i+1] ... up to v[n-1]. // 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) { func (v Vector) DoSome(i, n int, u Vector, c chan int) {
for ; i < n; i++ { for ; i &lt; n; i++ {
v[i] += u.Op(v[i]) v[i] += u.Op(v[i])
} }
c <- 1 // signal that this piece is done c &lt;- 1 // signal that this piece is done
} }
</pre> </pre>
<p> <p>
@ -2236,12 +2236,12 @@ const NCPU = 4 // number of CPU cores
func (v Vector) DoAll(u Vector) { func (v Vector) DoAll(u Vector) {
c := make(chan int, NCPU) // Buffering optional but sensible. c := make(chan int, NCPU) // Buffering optional but sensible.
for i := 0; i < NCPU; i++ { for i := 0; i &lt; NCPU; i++ {
go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c) go v.DoSome(i*len(v)/NCPU, (i+1)*len(v)/NCPU, u, c)
} }
// Drain the channel. // Drain the channel.
for i := 0; i < NCPU; i++ { for i := 0; i &lt; NCPU; i++ {
<-c // wait for one task to complete &lt;-c // wait for one task to complete
} }
// All done. // All done.
} }
@ -2282,12 +2282,12 @@ var serverChan = make(chan *Buffer)
func client() { func client() {
for { for {
b, ok := <-freeList // grab a buffer if available b, ok := &lt;-freeList // grab a buffer if available
if !ok { // if not, allocate a new one if !ok { // if not, allocate a new one
b = new(Buffer) b = new(Buffer)
} }
load(b) // read next message from the net load(b) // read next message from the net
serverChan <- b // send to server serverChan &lt;- b // send to server
} }
} }
</pre> </pre>
@ -2298,9 +2298,9 @@ and returns the buffer to the free list.
<pre> <pre>
func server() { func server() {
for { for {
b := <-serverChan // wait for work b := &lt;-serverChan // wait for work
process(b) process(b)
_ = freeList <- b // reuse buffer if room _ = freeList &lt;- b // reuse buffer if room
} }
} }
</pre> </pre>
@ -2377,7 +2377,7 @@ field for recoverable failures.
</p> </p>
<pre> <pre>
for try := 0; try < 2; try++ { for try := 0; try &lt; 2; try++ {
file, err = os.Open(filename, os.O_RDONLY, 0) file, err = os.Open(filename, os.O_RDONLY, 0)
if err == nil { if err == nil {
return return