GoBootcamp / book

Source code of the companion book/website
http://www.golangbootcamp.com/book
305 stars 85 forks source link

diff source book and online book #62

Open moonrich opened 8 years ago

moonrich commented 8 years ago

Please compile new version for online book

I found, Chapter 2: The Basics |> 2.7 Functions, signature, return values, named results The content of online book , still old than source book

rstrlcpy commented 8 years ago

still not fixed

l0010o0001l commented 7 years ago

To chime in, an example of the published version's content being different than the source code is the example code after the sentence, "If the result parameters are named, a return statement without arguments returns the current values of the results.":

Published:

func location(name, city string) (region, continent string) {
    switch city {
    case "New York", "LA", "Chicago":
        continent = "North America"
    default:
        continent = "Unknown"
    }
    return
}

func main() {
    region, continent := location("Matt", "LA")
    fmt.Printf("%s lives in %s", region, continent)
}

Source (and also in Go Playground):

package main

import "fmt"

func location(city string) (region, continent string) {
    switch city {
    case "Los Angeles", "LA", "Santa Monica":
        region, continent = "California", "North America"
    case "New York", "NYC":
        region, continent = "New York", "North America"
    default:
        region, continent = "Unknown", "Unknown"
    }
    return
}

func main() {
    region, continent := location("Santa Monica")
    fmt.Printf("Matt lives in %s, %s", region, continent)
}