Skip to content

Commit

Permalink
修复与更正 (unknwon#337)
Browse files Browse the repository at this point in the history
* Update 06.4.md

标点符号错误

* Update 06.5.md

* Update 06.6.md

* Update 06.8.md

修正上一节目录索引错误

* Update 06.8.md

* Update 07.0.md

* Update 07.1.md

* Update 07.6.md

用词不统一

* Update 08.0.md

* Update 08.6.md

用词不统一

* Update 09.0.md

* Update 09.5.md

修改不通顺

* 拼写错误

[建议加上`git remote -v`](https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/)

* Update 10.0.md

* 统一风格

* 调整位置,保证最后一行可以输出

* 保证最后一行可以输出

* 格式

* markdown 修改
  • Loading branch information
AutuanLiu authored and unknwon committed Mar 29, 2017
1 parent 967fe1e commit 6d3f190
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion eBook/06.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func a() {
```go
func f() {
for i := 0; i < 5; i++ {
defer fmt.Printf(%d , i)
defer fmt.Printf("%d ", i)
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions eBook/06.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Go 语言拥有一些不需要进行导入操作就可以使用的内置函数
|---|---|
|close|用于管道通信|
|len、cap|len 用于返回某个类型的长度或数量(字符串、数组、切片、map 和管道);cap 是容量的意思,用于返回某个类型的最大容量(只能用于切片和 map)|
|new、make|new 和 make 均是用于分配内存:new 用于值类型和用户定义的类型,如自定义结构,make 用户内置引用类型(切片、map 和管道)。它们的用法就像是函数,但是将类型作为参数:new(type)、make(type)。new(T) 分配类型 T 的零值并返回其地址,也就是指向类型 T 的指针(详见第 10.1 节)。它也可以被用于基本类型:`v := new(int)`。make(T) 返回类型 T 的初始化之后的值,因此它比 new 进行更多的工作(详见第 7.2.3/4 节、第 8.1.1 节和第 14.2.1 节)**new() 是一个函数,不要忘记它的括号**|
|new、make|new 和 make 均是用于分配内存:new 用于值类型和用户定义的类型,如自定义结构,make 用于内置引用类型(切片、map 和管道)。它们的用法就像是函数,但是将类型作为参数:new(type)、make(type)。new(T) 分配类型 T 的零值并返回其地址,也就是指向类型 T 的指针(详见第 10.1 节)。它也可以被用于基本类型:`v := new(int)`。make(T) 返回类型 T 的初始化之后的值,因此它比 new 进行更多的工作(详见第 7.2.3/4 节、第 8.1.1 节和第 14.2.1 节)**new() 是一个函数,不要忘记它的括号**|
|copy、append|用于复制和连接切片|
|panic、recover|两者均用于错误处理机制|
|print、println|底层打印函数(详见第 4.2 节),在部署环境中建议使用 fmt 包|
Expand All @@ -18,4 +18,4 @@ Go 语言拥有一些不需要进行导入操作就可以使用的内置函数

- [目录](directory.md)
- 上一节:[defer 和追踪](06.4.md)
- 下一节:[递归函数](06.6.md)
- 下一节:[递归函数](06.6.md)
2 changes: 1 addition & 1 deletion eBook/06.6.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 6.6 递归函数

当一个函数在其函数体内调用自身,则称之为递归。最经典的例子便是计算斐波那契数列,即每个数均为前两个数之和
当一个函数在其函数体内调用自身,则称之为递归。最经典的例子便是计算斐波那契数列,即前两个数为1,从第三个数开始每个数均为前两个数之和

数列如下所示:

Expand Down
4 changes: 2 additions & 2 deletions eBook/06.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ outside function body`),但可以被赋值于某个变量,即保存函数

```go
func() {
sum = 0.0
sum := 0.0
for i := 1; i <= 1e6; i++ {
sum += i
}
Expand Down Expand Up @@ -96,5 +96,5 @@ func main() {
## 链接

- [目录](directory.md)
- 上一节:[递归函数](06.6.md)
- 上一节:[将函数作为参数](06.7.md)
- 下一节:[应用闭包:将函数作为返回值](06.9.md)
2 changes: 1 addition & 1 deletion eBook/07.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
## 链接

- [目录](directory.md)
- 上一章[通过内存缓存来提升性能](06.12.md)
- 上一节[通过内存缓存来提升性能](06.12.md)
- 下一节:[声明和初始化](07.1.md)
2 changes: 1 addition & 1 deletion eBook/07.1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 7.1 声明和初始化

##7.1.1 概念
## 7.1.1 概念
数组是具有相同 **唯一类型** 的一组已编号且长度固定的数据项序列(这是一种同构的数据结构);这种类型可以是任意的原始类型例如整形、字符串或者自定义类型。数组长度必须是一个常量表达式,并且必须是一个非负整数。数组长度也是数组类型的一部分,所以[5]int和[10]int是属于不同类型的。数组的编译时值初始化是按照数组顺序完成的(如下)。

**注意事项** 如果我们想让数组元素类型为任意类型的话可以使用空接口作为类型(参考 [第 11 章](11.9.md))。当使用值时我们必须先做一个类型判断(参考 [第 11 章](11.3.md))。
Expand Down
2 changes: 1 addition & 1 deletion eBook/07.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func SearchStrings(a []string, x string) int
## 7.6.8 切片和垃圾回收
切片的底层指向一个数组,该数组的实际体积可能要大于切片所定义的体积。只有在没有任何切片指向的时候,底层的数组内层才会被释放,这种特性有时会导致程序占用多余的内存。
切片的底层指向一个数组,该数组的实际容量可能要大于切片所定义的容量。只有在没有任何切片指向的时候,底层的数组内层才会被释放,这种特性有时会导致程序占用多余的内存。
**示例** 函数 `FindDigits` 将一个文件加载到内存,然后搜索其中所有的数字并返回一个切片。
Expand Down
2 changes: 1 addition & 1 deletion eBook/08.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ map 这种数据结构在其他编程语言中也称为字典(Python)、hash
## 链接

- [目录](directory.md)
- 上一章[字符串、数组和切片的应用](07.6.md)
- 上一节[字符串、数组和切片的应用](07.6.md)
- 下一节:[声明、初始化和 make](08.1.md)
2 changes: 1 addition & 1 deletion eBook/08.6.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 8.6 将 map 的键值对调

这里倒置是指调换 key 和 value。如果 map 的值类型可以作为 key 且所有的 value 是唯一的,那么通过下面的方法可以简单的做到键值对调。
这里对调是指调换 key 和 value。如果 map 的值类型可以作为 key 且所有的 value 是唯一的,那么通过下面的方法可以简单的做到键值对调。

示例 8.7 [invert_map.go](examples/chapter_8/invert_map.go)

Expand Down
2 changes: 1 addition & 1 deletion eBook/09.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## 链接

- [目录](directory.md)
- 上一章[将 map 的键值对调](08.6.md)
- 上一节[将 map 的键值对调](08.6.md)
- 下一节:[标准库概述](09.1.md)
2 changes: 1 addition & 1 deletion eBook/09.5.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 9.5 自定义包和可见性

包是 Go 语言中代码组织和代码编译的主要方式。很多关于它们的基本信息已经在 4.2 章节中给出,最引人注目的便是可见性。现在我们来看看具体如何来使用自己写的包。在下一节,我们将回顾一些标准库中的包,自定义的包和标准库以外的包。
包是 Go 语言中代码组织和代码编译的主要方式。关于它们的很多基本信息已经在 4.2 章节中给出,最引人注目的便是可见性。现在我们来看看具体如何来使用自己写的包。在下一节,我们将回顾一些标准库中的包,自定义的包和标准库以外的包。

当写自己包的时候,要使用短小的不含有 `_`(下划线)的小写单词来为文件命名。这里有个简单例子来说明包是如何相互调用以及可见性是如何实现的。

Expand Down
2 changes: 1 addition & 1 deletion eBook/09.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
在云端创建一个新的 uc 仓库;发布的指令为(`NNNN` 替代用户名):

```
git remote add orign git@github.com:NNNN/uc.git
git remote add origin git@github.com:NNNN/uc.git
git push -u origin master
```

Expand Down
2 changes: 1 addition & 1 deletion eBook/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Go 通过类型别名(alias types)和结构体的形式支持用户自定义
## 链接

- [目录](directory.md)
- 上一章[在 Go 程序中使用外部库](09.11.md)
- 上一节[在 Go 程序中使用外部库](09.11.md)
- 下一节:[结构体定义](10.1.md)
1 change: 1 addition & 0 deletions eBook/10.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ func (n *NamedPoint) Abs() float64 {
主要有两种方法来实现在类型中嵌入功能:

A:聚合(或组合):包含一个所需功能类型的具名字段。

B:内嵌:内嵌(匿名地)所需功能类型,像前一节 10.6.5 所演示的那样。

为了使这些概念具体化,假设有一个 `Customer` 类型,我们想让它通过 `Log` 类型来包含日志功能,`Log` 类型只是简单地包含一个累积的消息(当然它可以是复杂的)。如果想让特定类型都具备日志功能,你可以实现一个这样的 `Log` 类型,然后将它作为特定类型的一个字段,并提供 `Log()`,它返回这个日志的引用。
Expand Down
6 changes: 3 additions & 3 deletions eBook/12.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func main() {
inputReader := bufio.NewReader(inputFile)
for {
inputString, readerError := inputReader.ReadString('\n')
fmt.Printf("The input was: %s", inputString)
if readerError == io.EOF {
return
}
fmt.Printf("The input was: %s", inputString)
}
}
}
```
Expand Down Expand Up @@ -75,7 +75,7 @@ func main() {
fmt.Printf("%s\n", string(buf))
err = ioutil.WriteFile(outputFile, buf, 0644) // oct, not hex
if err != nil {
panic(err. Error())
panic(err.Error())
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions eBook/16.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 16.2 误用字符串

当需要对一个字符串进行频繁的操作时,谨记在go语言中字符串是不可变的(类似java和c#)。使用诸如`a += b`形式连接字符串效率低下,尤其在一个循环内部使用这种形式。这会导致大量的内存开销和拷贝。**应该使用一个字符数组代替字符串,将字符串内容写入一个缓存中。**例如以下的代码示例:
当需要对一个字符串进行频繁的操作时,谨记在go语言中字符串是不可变的(类似java和c#)。使用诸如`a += b`形式连接字符串效率低下,尤其在一个循环内部使用这种形式。这会导致大量的内存开销和拷贝。**应该使用一个字符数组代替字符串,将字符串内容写入一个缓存中。** 例如以下的代码示例:

```go
var b bytes.Buffer
Expand All @@ -17,4 +17,4 @@ for condition {

- [目录](directory.md)
- 上一节:[误用短声明导致变量覆盖](16.1.md)
- 下一节:[发生错误时使用defer关闭一个文件](16.3.md)
- 下一节:[发生错误时使用defer关闭一个文件](16.3.md)
4 changes: 2 additions & 2 deletions eBook/examples/chapter_12/fileinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func main() {

for {
inputString, readerError := inputReader.ReadString('\n')
fmt.Printf("The input was: %s", inputString)
if readerError == io.EOF {
return // error or EOF
}
fmt.Printf("The input was: %s", inputString)
}
}
}

0 comments on commit 6d3f190

Please sign in to comment.