Skip to content

Commit

Permalink
builtin 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
achun committed Mar 25, 2013
1 parent 8cdeab3 commit dfab27a
Show file tree
Hide file tree
Showing 40 changed files with 756 additions and 5 deletions.
5 changes: 5 additions & 0 deletions builtin/ComplexType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type ComplexType complex64

功能说明:

ComplexType 在此只用作文档目的。 它代表所有的复数类型:即 complex64 或 complex128。
5 changes: 5 additions & 0 deletions builtin/FloatType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type FloatType float32

功能说明:

FloatType 在此只用作文档目的。 它代表所有的浮点数类型:即 float32 或 float64。
5 changes: 5 additions & 0 deletions builtin/IntegerType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type IntegerType int

功能说明:

IntegerType 在此只用作文档目的。 它代表所有的整数类型:如 int、uint、int8 等。
46 changes: 42 additions & 4 deletions builtin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# 包名
# builtin

函数列表
## 概述
builtin 包为Go的预声明标识符提供了文档. 此处列出的条目其实并不在 buildin 包中,对它们的描述只是为了让 godoc 给该语言的特殊标识符提供文档。

- xxx1
- xxx2
##包函数列表
- [func append(slice []Type, elems ...Type) []Type](append.md)
- [func close(c chan<- Type)](close.md)
- [func delete(m map[Type]Type1, key Type)](delete.md)
- [func panic(v interface{})](panic.md)
- [func recover() interface{}](recover.md)
- [type ComplexType](ComplexType.md)
- [func complex(r, i FloatType) ComplexType](complex.md)
- [type FloatType](FloatType.md)
func imag(c ComplexType) FloatType
func real(c ComplexType) FloatType
- [type IntegerType](IntegerType.md)
- [type Type](Type.md)
- [func make(Type, size IntegerType) Type](make.md)
- [func new(Type) *Type](new.md)
- [type Type1](Type1.md)
- [type bool](bool.md)
- [type byte](byte.md)
- [type complex128](complex128.md)
- [type complex64](complex64.md)
- [type error](error.md)
- [type float32](float32.md)
- [type float64](float64.md)
- [type int](int.md)
- [func cap(v Type) int](cap.md)
- [func copy(dst, src []Type) int](copy.md)
- [func len(v Type) int](len.md)
- [type int16](int16.md)
- [type int32](int32.md)
- [type int64](int64.md)
- [type int8](int8.md)
- [type rune](rune.md)
- [type string](string.md)
- [type uint](uint.md)
- [type uint16](uint16.md)
- [type uint32](uint32.md)
- [type uint64](uint64.md)
- [type uint8](uint8.md)
- [type uintptr](uintptr.md)
5 changes: 5 additions & 0 deletions builtin/Type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type Type int

功能说明:

Type 在此只用作文档目的。 它代表所有Go的类型,但对于任何给定的函数请求来说,它都代表与其相同的类型。
5 changes: 5 additions & 0 deletions builtin/Type1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type Type1 int

功能说明:

Type1 在此只用作文档目的。 它代表所有Go的类型,但对于任何给定的函数请求来说,它都代表与其相同的类型。
50 changes: 50 additions & 0 deletions builtin/append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## func append(slice []Type, elems ...Type) []Type

参数列表:

- slice Type类型切片
- elems Type类型元素
- ... 更多的Type类型元素

返回值:

- Type类型切片

功能说明:

append 内建函数将元素追加到切片的末尾。 若它有足够的容量,其目标就会重新切片以容纳新的元素。否则,就会分配一个新的基本数组。 append 返回更新后的切片。因此必须存储追加后的结果,通常为包含该切片自身的变量:

```go
slice = append(slice, elem1, elem2)
slice = append(slice, anotherSlice...)
```

代码实例:

```go
package main

import "fmt"

func main() {
a := []int{1, 2, 3, 4, 5}
s := a[1:3]
c := append(s, 6)
fmt.Println("a ==", a[:cap(a)])
fmt.Println("s ==", s[:cap(s)])
fmt.Println("c ==", c[:cap(c)])

d := append(a, 6)
fmt.Println("a ==", a[:cap(a)])
fmt.Println("d ==", d[:cap(d)])
}
```

输出:
~~~
a == [1 2 3 6 5]
s == [2 3 6 5]
c == [2 3 6 5]
a == [1 2 3 6 5]
d == [1 2 3 6 5 6 0 0 0 0]
~~~
5 changes: 5 additions & 0 deletions builtin/bool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type bool bool

功能说明:

bool 是布尔值的集合,即 true 和 false。
5 changes: 5 additions & 0 deletions builtin/byte.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type byte byte

功能说明:

byte 为 uint8 的别名,它完全等价于 uint8。 习惯上用它来区别字节值和8位无符号整数值。
23 changes: 23 additions & 0 deletions builtin/cap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## func cap(v Type) int

参数列表:

- v Type

返回值:

- int

功能说明:

The cap built-in function returns the capacity of v, according to its type:
cap 内建函数返回 v 的容量,返回值取决 v 的具体类型:


Channel: the channel buffer capacity, in units of elements;
if v is nil, cap(v) is zero.

数组:v 中元素的数量(与 len(v) 相同)。
数组指针:*v 中元素的数量(与 len(v) 相同)。
切片:在重新切片时,切片能够达到的最大缓存长度;若 v 为 nil,len(v) 即为零。
信道:以信道元素数量为单位返回信道缓存容量;若 v 为 nil,len(v) 即为零。
61 changes: 61 additions & 0 deletions builtin/close.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## func close(c chan<- Type)

参数列表:

- c 信道

返回值:

-

功能说明:

close 内建函数关闭信道,该信道必须为双向的或只发送的。 它只能由发送者执行,不应由接收者执行,其效果是在最后发送的值被接收后停止该信道。 已关闭的信道 c 中最后一个值被接收后,任何从信道 c 的接收操作都会无阻塞成功, 关闭的信道会返回该信道元素类型的零值。对于已关闭的信道,形式

```go
x, ok := <-c
```

还会将 ok 置为 false。

代码实例:

```go
package main

import (
"fmt"
)

func fibonacci(n int, c chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c) // 因为使用了range调用,必须 close(c)
}

func main() {
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c { // range 会不断从 channel 接收值,直到它被关闭。
fmt.Println(i)
}
}
```

输出:

~~~
0
1
1
2
3
5
8
13
21
34
~~~
32 changes: 32 additions & 0 deletions builtin/complex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## func complex(r, i FloatType) ComplexType

参数列表:

- r FloatType 实部
- i FloatType 虚部

返回值:

- ComplexType

功能说明:

complex 内建函数将两个浮点数值构造成一个复数值。 其实部和虚部的大小必须相同,即 float32 或 float64(或可赋予它们的),其返回值 即为对应的复数类型(complex64 对应 float32,complex128 对应 float64)。

代码实例:

```go
package main

import "fmt"

func main() {
fmt.Println(complex(10, 2))
}
```

输出:

~~~
(10+2i)
~~~
5 changes: 5 additions & 0 deletions builtin/complex128.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type complex128 complex128

功能说明:

complex128 是所有实部和虚部为 float64 的复数集合。
5 changes: 5 additions & 0 deletions builtin/complex64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## type complex64 complex64

功能说明:

complex64 是所有实部和虚部为 float32 的复数集合。
41 changes: 41 additions & 0 deletions builtin/copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## func copy(dst, src []Type) int

参数列表:

- dst []Type 与 src 同类型
- src []Type

返回值:

- int 返回被复制的元素数量

功能说明:

copy 内建函数将元素从来源切片复制到目标切片中。 (特殊情况是,它也能将字节从字符串复制到字节切片中)。来源和目标可以重叠。 copy 返回被复制的元素数量,它会是 len(src) 和 len(dst) 中较小的那个。

代码实例:

```go
package main

import "fmt"

func main() {
src := []int{1, 2, 3, 4, 5}
dst := make([]int, 3)
len := copy(dst, src[4:])
fmt.Println(len, dst)
len = copy(dst, src[0:])
fmt.Println(len, dst)
len = copy(dst, src)
fmt.Println(len, dst)
}
```

输出:

~~~
1 [5 0 0]
3 [1 2 3]
3 [1 2 3]
~~~
56 changes: 56 additions & 0 deletions builtin/delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## func delete(m map[Type]Type1, key Type)

参数列表:

- m map
- key 键

返回值:

-

功能说明:

delete 内建函数按照指定的键将元素从映射中删除。如果元素不存在,delete 为空操作。如果 m 为 nil,delete 引发 panic 错误。

代码实例:

```go
package main

import "fmt"

type Vertex struct {
Lat, Long float64
}

var m map[string]Vertex

var nilmap map[string]Vertex

func main() {
m = make(map[string]Vertex)
m["Bell Labs"] = Vertex{
40.68433, -74.39967,
}
delete(m, "key")
fmt.Println(m)
delete(m, "Bell Labs")
fmt.Println(m)

delete(nilmap, "key")

}
```

输出:

~~~
map[Bell Labs:{40.68433 -74.39967}]
map[]
panic: runtime error: deletion of entry in nil map
goroutine 1 [running]:
main.main()
/tmpfs/gosandbox-ffb3cedf_c062e804_9b5b7ada_f200355f_78578d79/prog.go:23 +0x1e0
~~~
10 changes: 10 additions & 0 deletions builtin/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## type error
~~~go
type error interface {
Error() string
}
~~~

功能说明:

error 内建接口类型是表示错误情况的约定接口,nil 值即表示没有错误。
Loading

0 comments on commit dfab27a

Please sign in to comment.