mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 02:35:53 +08:00
add 04.4.md translate for ch 4.4
This commit is contained in:
15
eBook/examples/chapter_4/function_calls_function.go
Normal file
15
eBook/examples/chapter_4/function_calls_function.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
var a string
|
||||
func main() {
|
||||
a = "G"
|
||||
print(a)
|
||||
f1()
|
||||
}
|
||||
func f1() {
|
||||
a := "O"
|
||||
print(a)
|
||||
f2()
|
||||
}
|
||||
func f2() {
|
||||
print(a)
|
||||
}
|
14
eBook/examples/chapter_4/global_scope.go
Normal file
14
eBook/examples/chapter_4/global_scope.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
var a = "G"
|
||||
func main() {
|
||||
n()
|
||||
m()
|
||||
n()
|
||||
}
|
||||
func n() {
|
||||
print(a)
|
||||
}
|
||||
func m() {
|
||||
a = "O"
|
||||
print(a)
|
||||
}
|
11
eBook/examples/chapter_4/goos.go
Normal file
11
eBook/examples/chapter_4/goos.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
func main() {
|
||||
var goos string = os.Getenv("GOOS")
|
||||
fmt.Printf("The operating system is: %s\n", goos)
|
||||
path := os.Getenv("PATH")
|
||||
fmt.Printf("Path is %s\n", path)
|
||||
}
|
6
eBook/examples/chapter_4/init.go
Normal file
6
eBook/examples/chapter_4/init.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package trans
|
||||
import "math"
|
||||
var Pi float64
|
||||
func init() {
|
||||
Pi = 4 * math.Atan(1) // init() function computes Pi
|
||||
}
|
12
eBook/examples/chapter_4/local_scope.go
Normal file
12
eBook/examples/chapter_4/local_scope.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
var a = "G"
|
||||
func main() {
|
||||
n()
|
||||
m()
|
||||
n()
|
||||
}
|
||||
func n() { print(a) }
|
||||
func m() {
|
||||
a := "O"
|
||||
print(a)
|
||||
}
|
9
eBook/examples/chapter_4/user_init.go
Normal file
9
eBook/examples/chapter_4/user_init.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"./trans"
|
||||
)
|
||||
var twoPi = 2 * trans.Pi
|
||||
func main() {
|
||||
fmt.Printf("2*Pi = %g\n", twoPi) // 2*Pi = 6.283185307179586
|
||||
}
|
Reference in New Issue
Block a user