開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 15(responding to requests - Web Apps)、Pool Puzzle(439)の解答を求めてみる。
コード
package main
import "fmt"
func callFunction(passedFunction func()) {
passedFunction()
}
func callTwice(passedFunction func()) {
passedFunction()
passedFunction()
}
func callWithArguments(passedFunction func(string, bool)) {
passedFunction("this sentence is", false)
}
func printReturnValue(passedFunction func() string) {
fmt.Println(passedFunction())
}
func functionA() {
fmt.Println("function called")
}
func functionB() string {
fmt.Println("function called")
return "Returning from function"
}
func functionC(a string, b bool) {
fmt.Println("function called")
fmt.Println(a, b)
}
func main() {
callFunction(functionA)
callTwice(functionA)
callWithArguments(functionC)
printReturnValue(functionB)
}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go run sample2.go function called function called function called function called this sentence is false function called Returning from function $
0 コメント:
コメントを投稿