Skip to content

Commit a5e10ed

Browse files
committed
doc/play: don't use println in examples
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6849105
1 parent 2e73453 commit a5e10ed

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

doc/play/fib.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

3+
import "fmt"
4+
35
// fib returns a function that returns
46
// successive Fibonacci numbers.
57
func fib() func() int {
@@ -13,5 +15,5 @@ func fib() func() int {
1315
func main() {
1416
f := fib()
1517
// Function calls are evaluated left-to-right.
16-
println(f(), f(), f(), f(), f())
18+
fmt.Println(f(), f(), f(), f(), f())
1719
}

doc/play/sieve.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package main
44

5+
import "fmt"
6+
57
// Send the sequence 2, 3, 4, ... to channel 'ch'.
68
func Generate(ch chan<- int) {
79
for i := 2; ; i++ {
@@ -26,7 +28,7 @@ func main() {
2628
go Generate(ch) // Launch Generate goroutine.
2729
for i := 0; i < 10; i++ {
2830
prime := <-ch
29-
print(prime, "\n")
31+
fmt.Println(prime)
3032
ch1 := make(chan int)
3133
go Filter(ch, ch1, prime)
3234
ch = ch1

doc/play/solitaire.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var board = []rune(
2828
...........
2929
`)
3030

31-
// center is the position of the center hole if
31+
// center is the position of the center hole if
3232
// there is a single one; otherwise it is -1.
3333
var center int
3434

@@ -47,7 +47,7 @@ func init() {
4747

4848
var moves int // number of times move is called
4949

50-
// move tests if there is a peg at position pos that
50+
// move tests if there is a peg at position pos that
5151
// can jump over another peg in direction dir. If the
5252
// move is valid, it is executed and move returns true.
5353
// Otherwise, move returns false.
@@ -69,11 +69,11 @@ func unmove(pos, dir int) {
6969
board[pos+2*dir] = '○'
7070
}
7171

72-
// solve tries to find a sequence of moves such that
73-
// there is only one peg left at the end; if center is
72+
// solve tries to find a sequence of moves such that
73+
// there is only one peg left at the end; if center is
7474
// >= 0, that last peg must be in the center position.
7575
// If a solution is found, solve prints the board after
76-
// each move in a backward fashion (i.e., the last
76+
// each move in a backward fashion (i.e., the last
7777
// board position is printed first, all the way back to
7878
// the starting board position).
7979
func solve() bool {
@@ -89,7 +89,7 @@ func solve() bool {
8989
// see if this new board has a solution
9090
if solve() {
9191
unmove(pos, dir)
92-
println(string(board))
92+
fmt.Println(string(board))
9393
return true
9494
}
9595
unmove(pos, dir)
@@ -102,7 +102,7 @@ func solve() bool {
102102
// tried each possible move
103103
if n == 1 && (center < 0 || last == center) {
104104
// there's only one peg left
105-
println(string(board))
105+
fmt.Println(string(board))
106106
return true
107107
}
108108
// no solution found for this board

doc/play/tree.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// express concurrent concepts, such as
33
// this binary tree comparison.
44
//
5-
// Trees may be of different shapes,
5+
// Trees may be of different shapes,
66
// but have the same contents. For example:
77
//
88
// 4 6
@@ -29,7 +29,7 @@ type Tree struct {
2929
Right *Tree
3030
}
3131

32-
// Walk traverses a tree depth-first,
32+
// Walk traverses a tree depth-first,
3333
// sending each Value on a channel.
3434
func Walk(t *Tree, ch chan int) {
3535
if t == nil {

0 commit comments

Comments
 (0)