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

doc/codewalk/functions.xml: Fix broken function examples

I removed the broken function comparison example and fixed a code highlighting regexp.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5501078
This commit is contained in:
John DeNero 2012-01-03 12:15:08 +11:00 committed by Andrew Gerrand
parent a274798d6e
commit c2b87ce007
2 changed files with 1 additions and 14 deletions

View File

@ -45,7 +45,7 @@
turn. turn.
</step> </step>
<step title="Multiple return values" src="doc/codewalk/pig.go:/\/\/ roll returns/,/stay.*true\n}/"> <step title="Multiple return values" src="doc/codewalk/pig.go:/\/\/ roll returns/,/true\n}/">
Go functions can return multiple values. Go functions can return multiple values.
<br/><br/> <br/><br/>
@ -82,16 +82,6 @@
associated with the current player. associated with the current player.
</step> </step>
<step title="Comparing functions" src="doc/codewalk/pig.go:/if action/,/currentPlayer\)\)\n\t\t}/">
Functions can be compared for equality in Go. From the
<a href="http://golang.org/doc/go_spec.html#Comparison_operators">language specification</a>:
Function values are equal if they refer to the same function or if both are <code>nil</code>.
<br/><br/>
We enforce that a <code>strategy</code> function can only return a legal
<code>action</code>: either <code>roll</code> or <code>stay</code>.
</step>
<step title="Simulating a tournament" src="doc/codewalk/pig.go:/\/\/ roundRobin/,/gamesPerStrategy\n}/"> <step title="Simulating a tournament" src="doc/codewalk/pig.go:/\/\/ roundRobin/,/gamesPerStrategy\n}/">
The <code>roundRobin</code> function simulates a tournament and tallies wins. The <code>roundRobin</code> function simulates a tournament and tallies wins.
Each strategy plays each other strategy <code>gamesPerSeries</code> times. Each strategy plays each other strategy <code>gamesPerSeries</code> times.

View File

@ -61,9 +61,6 @@ func play(strategy0, strategy1 strategy) int {
currentPlayer := rand.Intn(2) // Randomly decide who plays first currentPlayer := rand.Intn(2) // Randomly decide who plays first
for s.player+s.thisTurn < win { for s.player+s.thisTurn < win {
action := strategies[currentPlayer](s) action := strategies[currentPlayer](s)
if action != roll && action != stay {
panic(fmt.Sprintf("Player %d is cheating", currentPlayer))
}
s, turnIsOver = action(s) s, turnIsOver = action(s)
if turnIsOver { if turnIsOver {
currentPlayer = (currentPlayer + 1) % 2 currentPlayer = (currentPlayer + 1) % 2