-3
圍棋遊的intepreter我有以下幾點:main.go:9:使用STR包沒有選擇
package main
import (
"golang.org/x/tour/wc"
str "strings"
)
func WordCount(s string) map[string]int {
results := make(map[str]int)
words := str.Fields(s)
return map[string]int{"x": 1}
}
//func main() {
// wc.Test(WordCount)
//}
這是基於https://tour.golang.org/moretypes/23
我的錯誤是
tmp/sandbox169629521/main.go:9: use of package str without selector
試圖
results := make(map[str.string]int)
現在失敗
tmp/sandbox424441423/main.go:9: cannot refer to unexported name strings.string
tmp/sandbox424441423/main.go:9: undefined: strings.string
除了'string'是一個內建類型,除非你要不要重命名進口。當其他人通過名稱'strings'知道包時,沒有理由嘗試使用'str'而不是'strings'。 – JimB