Golang
- 6. CERL 頁厘亟議匯倖 C++ 殻會垂函吭噐Erlang For
C/C++。徽恷嶮凪糞 CERL 音頁匯倖園殻袈塀窃貌噐
Erlang 議叫廉遇厚麒拝燦鴨侘井云議 Golang。
!!俯塀琉
- 16. 危列
func main() {
file, err := os.Open("hello.txt")
if err != nil {
return
}
defer file.Close()
// use file
}
- 17. 械
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("recover", r)
}
}()
someFunc()
}
func someFunc() {
panic("[fail]")
}
- 18. 短嗤窃
type Vertex struct {
X, Y float64
}
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := &Vertex{3, 4}
fmt.Println(v.Abs())
}
- 19. 短嗤写覚
type Egg struct {
weight int
}
type Animal struct {
weight int
}
type Bird struct {
Animal
egg Egg
}
- 20. 俊笥
type Abser interface {
Abs() float64
}
type MyFloat float64
func (f MyFloat) Abs() float64 {
if f < 0 {
return float64(-f)
}
return float64(f)
}
- 25. 窃Actor佩葎
var ch = make(chan int)
func myActor() {
data := <-ch
// use data
}
func main() {
go myActor()
ch <- 1
}
- 26. 亘殻
揖化旗鷹 化丼惚
掲農媼塀
汽潦綿杵
涙潦滅仍撮涙迄
尖胎貧辛參涙涕坪贋渣藤
- 30. 芦廾宥狛坿鷹
$ hg clone -u release https://code.google.com/p/go
$ cd go/src
$ ./all.bash