]> Cypherpunks repositories - gostls13.git/commitdiff
doc/play: don't use println in examples
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 26 Nov 2012 21:05:18 +0000 (13:05 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 26 Nov 2012 21:05:18 +0000 (13:05 -0800)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6849105

doc/play/fib.go
doc/play/sieve.go
doc/play/solitaire.go
doc/play/tree.go

index 42da9ce82e9b7e4192049a5cf4e4d87d92ad5a47..19e4721028685f99d54eec4719001d2544afd3d8 100644 (file)
@@ -1,5 +1,7 @@
 package main
 
+import "fmt"
+
 // fib returns a function that returns
 // successive Fibonacci numbers.
 func fib() func() int {
@@ -13,5 +15,5 @@ func fib() func() int {
 func main() {
        f := fib()
        // Function calls are evaluated left-to-right.
-       println(f(), f(), f(), f(), f())
+       fmt.Println(f(), f(), f(), f(), f())
 }
index 585507ac4442d2e2cce9d8a701cadff86429b300..519093453f7d272f71fbc02e065d2987f2a953f9 100644 (file)
@@ -2,6 +2,8 @@
 
 package main
 
+import "fmt"
+
 // Send the sequence 2, 3, 4, ... to channel 'ch'.
 func Generate(ch chan<- int) {
        for i := 2; ; i++ {
@@ -26,7 +28,7 @@ func main() {
        go Generate(ch)      // Launch Generate goroutine.
        for i := 0; i < 10; i++ {
                prime := <-ch
-               print(prime, "\n")
+               fmt.Println(prime)
                ch1 := make(chan int)
                go Filter(ch, ch1, prime)
                ch = ch1
index 759d5428151b48bfa9c5b26f854dd2ea91e7d40f..15022aa1949dcd17017b8cd74c853fc047295a8c 100644 (file)
@@ -28,7 +28,7 @@ var board = []rune(
 ...........
 `)
 
-// center is the position of the center hole if 
+// center is the position of the center hole if
 // there is a single one; otherwise it is -1.
 var center int
 
@@ -47,7 +47,7 @@ func init() {
 
 var moves int // number of times move is called
 
-// move tests if there is a peg at position pos that 
+// move tests if there is a peg at position pos that
 // can jump over another peg in direction dir. If the
 // move is valid, it is executed and move returns true.
 // Otherwise, move returns false.
@@ -69,11 +69,11 @@ func unmove(pos, dir int) {
        board[pos+2*dir] = '○'
 }
 
-// solve tries to find a sequence of moves such that 
-// there is only one peg left at the end; if center is 
+// solve tries to find a sequence of moves such that
+// there is only one peg left at the end; if center is
 // >= 0, that last peg must be in the center position.
 // If a solution is found, solve prints the board after
-// each move in a backward fashion (i.e., the last 
+// each move in a backward fashion (i.e., the last
 // board position is printed first, all the way back to
 // the starting board position).
 func solve() bool {
@@ -89,7 +89,7 @@ func solve() bool {
                                        // see if this new board has a solution
                                        if solve() {
                                                unmove(pos, dir)
-                                               println(string(board))
+                                               fmt.Println(string(board))
                                                return true
                                        }
                                        unmove(pos, dir)
@@ -102,7 +102,7 @@ func solve() bool {
        // tried each possible move
        if n == 1 && (center < 0 || last == center) {
                // there's only one peg left
-               println(string(board))
+               fmt.Println(string(board))
                return true
        }
        // no solution found for this board
index 5bcbf05a882d5793593f263ebe64be0a77fba40f..3790e6cda50fae2f3cdcd270a9f123439618df8d 100644 (file)
@@ -2,7 +2,7 @@
 // express concurrent concepts, such as
 // this binary tree comparison.
 //
-// Trees may be of different shapes, 
+// Trees may be of different shapes,
 // but have the same contents. For example:
 //
 //        4               6
@@ -29,7 +29,7 @@ type Tree struct {
        Right *Tree
 }
 
-// Walk traverses a tree depth-first, 
+// Walk traverses a tree depth-first,
 // sending each Value on a channel.
 func Walk(t *Tree, ch chan int) {
        if t == nil {