摘要: Let's have some fun with functions.Implement afibonaccifunction that returns a function (a closure) that returns successive fibonacci numbers.package ... 阅读全文
posted @ 2014-10-27 23:44 wuhn 阅读(357) 评论(0) 推荐(0) 编辑
摘要: Go functions may be closures. A closure is a function value that references variables from outside its body. The function may access and assign to the... 阅读全文
posted @ 2014-10-27 23:30 wuhn 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Functions are values too.在函数式语言中中函数都是变量,比如在javascript中package main import ( "fmt" "math")func main() { hypot := func(x,y float64) float64 { ... 阅读全文
posted @ 2014-10-27 23:25 wuhn 阅读(132) 评论(0) 推荐(0) 编辑
摘要: ImplementWordCount. It should return a map of the counts of each “word” in the strings. Thewc.Testfunction runs a test suite against the provided func... 阅读全文
posted @ 2014-10-27 23:21 wuhn 阅读(258) 评论(0) 推荐(0) 编辑
摘要: Insert or update an element in mapm:m[key] = elemRetrieve an element:elem = m[key]Delete an element:delete(m, key)Test that a key is present with a tw... 阅读全文
posted @ 2014-10-27 23:11 wuhn 阅读(110) 评论(0) 推荐(0) 编辑
摘要: If the top-level type is just a type name, you can omit it from the elements of the literal.package main import "fmt"type Vertex struct { Lat, Long... 阅读全文
posted @ 2014-10-27 23:04 wuhn 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Map literals are like struct literals, but the keys are required.package main import "fmt"type Vertex struct { Lat, Long float64}var m = map[string... 阅读全文
posted @ 2014-10-27 22:54 wuhn 阅读(153) 评论(0) 推荐(0) 编辑
摘要: A map maps keys to values.Maps must be created withmake(notnew) before use; thenilmap is empty and cannot be assigned to.package main import "fmt"type... 阅读全文
posted @ 2014-10-27 22:51 wuhn 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 下面的不是指针指向数组,而是指针指向SliceI'm having a little play with google's Go language, and I've run into something which is fairly basic in C but doesn't seem to ... 阅读全文
posted @ 2014-10-27 22:41 wuhn 阅读(220) 评论(0) 推荐(0) 编辑
摘要: ImplementPic. It should return a slice of lengthdy, each element of which is a slice ofdx8-bit unsigned integers. When you run the program, it will di... 阅读全文
posted @ 2014-10-27 02:28 wuhn 阅读(277) 评论(0) 推荐(0) 编辑
摘要: You can skip the index or value by assigning to_.If you only want the index, drop the ", value" entirely.package main import "fmt"func main() { pow... 阅读全文
posted @ 2014-10-27 02:27 wuhn 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Therangeform of theforloop iterates over a slice or map.package mainimport "fmt"var pow = []int{1, 2, 4, 8, 16, 32, 64, 128}func main() { for i, v ... 阅读全文
posted @ 2014-10-27 01:56 wuhn 阅读(160) 评论(0) 推荐(0) 编辑
摘要: IntroductionGo's slice type provides a convenient and efficient means of working with sequences of typed data. Slices are analogous to arrays in other... 阅读全文
posted @ 2014-10-27 01:51 wuhn 阅读(244) 评论(0) 推荐(0) 编辑
摘要: The zero value of a slice isnil.A nil slice has a length and capacity of 0.(To learn more about slices, read theSlices: usage and internalsarticle.)pa... 阅读全文
posted @ 2014-10-27 01:15 wuhn 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Slices are created with themakefunction. It works by allocating a zeroed array and returning a slice that refers to that array:a := make([]int, 5) //... 阅读全文
posted @ 2014-10-27 01:13 wuhn 阅读(135) 评论(0) 推荐(0) 编辑
摘要: ---恢复内容开始---Slices can be re-sliced, creating a new slice value that points to the same array.The expressions[lo:hi]evaluates to a slice of the elemen... 阅读全文
posted @ 2014-10-27 01:07 wuhn 阅读(114) 评论(0) 推荐(0) 编辑
摘要: A slice points to an array of values and also includes a length.[]Tis a slice with elements of typeT.package main import "fmt"func main() { p := []... 阅读全文
posted @ 2014-10-27 01:02 wuhn 阅读(171) 评论(0) 推荐(0) 编辑
摘要: The type[n]Tis an array ofnvalues of typeT.The expressionvar a [10]intdeclares a variableaas an array of ten integers.An array's length is part of its... 阅读全文
posted @ 2014-10-27 00:59 wuhn 阅读(121) 评论(0) 推荐(0) 编辑
摘要: The expressionnew(T)allocates a zeroedTvalue and returns a pointer to it.var t *T = new(T)ort := new(T)package main import "fmt"type Vertex struct { ... 阅读全文
posted @ 2014-10-27 00:50 wuhn 阅读(131) 评论(0) 推荐(0) 编辑
摘要: A struct literal denotes a newly allocated struct value by listing the values of its fields.You can list just a subset of fields by using theName:synt... 阅读全文
posted @ 2014-10-27 00:48 wuhn 阅读(179) 评论(0) 推荐(0) 编辑