Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EngineerX.go#1 - A Tour of Goで一緒にGo入門 : 基本構文編 -

Fumi
September 28, 2019

EngineerX.go#1 - A Tour of Goで一緒にGo入門 : 基本構文編 -

# イベント
EngineerX.go#1
A Tour of Goで一緒にGo入門と税理士さんによる税金のお話
https://engineerx-go.connpass.com/event/143495/

## イベント概要
合同会社TsujiTechが主催するEngineerXは、『エンジニア×異種業界 の勉強会』を開催しているグループです。
ここでのエンジニアとは、技術を使ってモノを作り出す方を指し、異種業界はそれ以外の活動をしている方を指します。
私たちは、「エンジニアが世界を創る」と意識し、エンジニアに成長・活躍する場を提供します。
本勉強会を通して、技術の向上だけでなく、新しいサービスが生まれたり、開発の仲間を見つけたり、独立・副業をする際に気になるお金の話や法律の話などを聞ける士業をされている方と交流したりできるようにしたいと考えています。

その中でGoの勉強会に特化したのがEngineerX.goです。
一緒にGoを勉強して、Gophersとして確かな力をつけるのが目的です。

# 概要
今回は「A Tour of Go」を通してGoに入門しよう!っという内容です。
「A Tour of Go」の基本構文を取り扱いました。

Fumi

September 28, 2019
Tweet

More Decks by Fumi

Other Decks in Programming

Transcript

  1. A T O U R O F G O ⼀

    緒 に G O の 世 界 を 冒 険 し よ う ︕ EngineerX.go #1 The Gopher character is based on the Go mascot designed by Renée French.
  2. ABOUT GO G o は 、 シ ン プ ル

    で 信 頼 性 の ⾼ い 効 率 的 な ソ フ ト ウ ェ ア を 簡 単 に 構 築 で き る オ ー プ ン ソ ー ス の プ ロ グ ラ ミ ン グ ⾔ 語 で す 。 (By https://golang.org/)
  3. GO RELEASE HISTORY 2012.03.28 go1 2013.05.13 go1.1 2013.12.01 go1.2 2014.06.18

    go1.3 2014.12.10 go1.4 2015.08.19 go1.5 2016.02.17 go1.6 2016.08.15 go1.7 2017.02.16 go1.8 2017.08.24 go1.9 2018.02.16 go1.10 2018.08.24 go1.11 2019.02.25 go1.12 2019.09.03 go1.13
  4. GO HISTORY • What is the history of the project?

    Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on the white board on September 21, 2007. Within a few days the goals had settled into a plan to do something and a fair idea of what it would be. Design continued part-time in parallel with unrelated work. By January 2008, Ken had started work on a compiler with which to explore ideas; it generated C code as its output. By mid-year the language had become a full-time project and had settled enough to attempt a production compiler. In May 2008, Ian Taylor independently started on a GCC front end for Go using the draft specification. Russ Cox joined in late 2008 and helped move the language and libraries from prototype to reality. Go became a public open source project on November 10, 2009. Countless people from the community have contributed ideas, discussions, and code. There are now millions of Go programmers—gophers—around the world, and there are more every day. Go's success has far exceeded our expectations. (By https://golang.org/doc/faq#history) Robert Griesemer Rob Pike Ken Thompson
  5. GO HISTORY • What is the history of the project?

    Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on the white board on September 21, 2007. Within a few days the goals had settled into a plan to do something and a fair idea of what it would be. Design continued part-time in parallel with unrelated work. By January 2008, Ken had started work on a compiler with which to explore ideas; it generated C code as its output. By mid-year the language had become a full-time project and had settled enough to attempt a production compiler. In May 2008, Ian Taylor independently started on a GCC front end for Go using the draft specification. Russ Cox joined in late 2008 and helped move the language and libraries from prototype to reality. Go became a public open source project on November 10, 2009. Countless people from the community have contributed ideas, discussions, and code. There are now millions of Go programmers—gophers—around the world, and there are more every day. Go's success has far exceeded our expectations. (By https://golang.org/doc/faq#history) ロバート・グリーズマーのツイート(Fumiの意訳) 今⽇(9⽉21⽇)から12年前、2007年9⽉20⽇、 私は私が信頼しているロブ・パイク、ケン・トンプソンとともに数分間仕事を忘れ、 そしてその時より良いコードが書ける⽅法を決めた。 9⽉25⽇にロブはGoという名前を提案し、それがすべての始まりだ。右肩上がり、前向きに進む、苦あれば楽あり。
  6. よく⾔われること Goが成功している理由 Goの成功している理由 • コンパイルの速さ • 実⾏の速さ • デプロイの容易さ •

    ツール(go tool) • 標準ライブラリ (By Go Conference 2014 Autumn) ⾔語の特徴 • 並⾏プログラム • インターフェース etc. Pob Pike⽒が考える成功の理由 GoのSimplicity(単純さ)
  7. A TOUR OF GO ⼀緒にGoの世界を冒険しよう︕ https://tour.golang.org/ 「Imports Off」と表⽰してある時︓ 機能OFF状態 「Imports

    On」と表⽰してある時︓ 「Format」をクリックして整形する際に、 必要なパッケージのimport⽂を⾃動で書いてくれ、 不要な場合は取り除いてくれる
  8. A TOUR OF GO ⼀緒にGoの世界を冒険しよう︕ https://tour.golang.org/ 「Syntax Off」と表⽰してある時︓ 機能OFF状態 「

    Syntax On」と表⽰してある時︓ エディタ内のコードをシンタックスハイライトする
  9. A TOUR OF GO ⼀緒にGoの世界を冒険しよう︕ • 基本構⽂ – パッケージ、変数、関数 –

    制御⽂︓for, if, else, switch, defer – その他の型︓struct, slices, maps • メソッドとインタフェース – メソッドとインタフェース • 並⾏性 – 並⾏性 A Tour of Goの構成
  10. A TOUR OF GO ⼀緒にGoの世界を冒険しよう︕ • 基本構⽂ – パッケージ、変数、関数 –

    制御⽂︓for, if, else, switch, defer – その他の型︓struct, slices, maps • メソッドとインタフェース – メソッドとインタフェース • 並⾏性 – 並⾏性 本 ⽇ の 範 囲 A Tour of Goの構成 ※練習問題(Exercise)はやりません
  11. A TOUR OF GO ⼀緒にGoの世界を冒険しよう︕ • 基本構⽂ – パッケージ、変数、関数 –

    制御⽂︓for, if, else, switch, defer – その他の型︓struct, slices, maps • メソッドとインタフェース – メソッドとインタフェース • 並⾏性 – 並⾏性 本 ⽇ の 範 囲 A Tour of Goの構成 ※練習問題(Exercise)はやりません
  12. PACKAGE DirPath: $GOROOT ./math/rand ├── example_test.go ├── exp.go ├── gen_cooked.go

    ├── normal.go ├── race_test.go ├── rand.go ├── rand_test.go ├── regress_test.go ├── rng.go └── zipf.go
  13. PACKAGE DirPath: $GOROOT ./math/rand ├── example_test.go ├── exp.go ├── gen_cooked.go

    ├── normal.go ├── race_test.go ├── rand.go ├── rand_test.go ├── regress_test.go ├── rng.go └── zipf.go
  14. EXPORTED NAMES DirPath: $GOROOT ./math ├── … ├── atan.go ├──

    atan2.go ├── atanh.go ├── bits.go ├── cbrt.go ├── const.go ├── copysign.go ├── dim.go ├── erf.go …
  15. FUNCTIONS func add(x int, y int) int { return x

    + y } 変数名の後に型を書く
  16. FUNCTIONS func add(x int, y int) int { return x

    + y } ちなみに、以下のようには書けない
  17. BASIC TYPES 基本型(組み込み型)︓20種類 bool string int int8 int16 int32 int64

    uint uint8 uint16 uint32 uint64 uintptr byte // uint8 の別名 rune // int32 の別名 // Unicode の符号点(code point) float32 float64 complex64 complex128 error https://golang.org/ref/spec#Predeclared_identifiers
  18. bool string int int8 int16 int32 int64 uint uint8 uint16

    uint32 uint64 uintptr byte // uint8 の別名 rune // int32 の別名 // Unicode の符号点(code point) float32 float64 complex64 complex128 error BASIC TYPES int, uint, uintprt型は 32-bitシステムでは32bit(4byte)で、 64-bitシステムでは64bit(8byte)になる 基本型(組み込み型)︓20種類 https://golang.org/ref/spec#Predeclared_identifiers
  19. BASIC TYPES 基本型(組み込み型)︓20種類 bool string int int8 int16 int32 int64

    uint uint8 uint16 uint32 uint64 uintptr byte // uint8 の別名 rune // int32 の別名 // Unicode の符号点(code point) float32 float64 complex64 complex128 error https://golang.org/ref/spec#Predeclared_identifiers サイズ、符号なし(unsigned)整数の型を使う特別な理由がない限り、 整数の変数が必要な時は int を使いましょう
  20. ZERO VALUES ゼロ値は型によって それぞれ以下のように与えられる 数値型(int, floatなど) 0 bool型 false string型

    " " (空⽂字列) 変数に初期値を与えずに宣⾔すると ゼロ値(Zero Value)が与えられる
  21. TYPE CONVERSIONS math.Sqrt関数はfloat64を型に取るため、 intからfloat64へ型変換を⾏なっている Goでの型変換は、 明⽰的な型変換を強制されている 型変換 変数 v 、型

    T があった場合、 T(v) は、変数 v を T 型へ変換 暗黙的な型変換が⾏われないため、 適切な型を扱ってコードが書ける ゆえに、バグを作りにくくしている
  22. TYPE INFERENCE 右側の変数が型を持っている場合 右側に型を指定しない定数である場合 var i int j := i

    // j は i と同じint型になる i := 42 // int f := 3.142 // float64 g := 0.867 + 0.5i // complex128
  23. 0 0 0 1 0 0 1 0 0 0

    1 1 0 1 0 0 (例)16-bitのデータがった時、 元のデータ (16-bit, 0x2468) 蛇足
  24. 格納領域 (8-bit, 0x????) 0 0 0 1 0 0 1

    0 0 0 1 1 0 1 0 0 元のデータ (16-bit, 0x2468) (例) 16-bitのデータがった時、8-bitの領域に格納しようとすると… 蛇足
  25. 0 0 0 1 0 0 1 0 0 0

    1 1 0 1 0 0 0 1 1 0 1 0 0 0 格納領域 (8-bit, 0x0068) 上位8-bitのデータ消失 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 元のデータ (16-bit, 0x2468) (例) 16-bitのデータがった時、8-bitの領域に格納しようとすると… 蛇足
  26. FOR for i := 0 ; i < 10 ;

    i++ { … } 初期化⽂ (the init statement) 条件式 (the condition expression) 後処理⽂ (the post statement) for ⽂は、セミコロン(;)によって、以下の3つの部分に分かれている
  27. FOR for i := 0 ; i < 10 ;

    i++ { … } 初期化⽂ (the init statement) 条件式 (the condition expression) 後処理⽂ (the post statement) for ⽂は、セミコロン(;)によって、以下の3つの部分に分かれている 短い変数宣⾔によく利⽤する その変数はfor⽂のスコープ内のみ有効
  28. FOR for i := 0 ; i < 10 ;

    i++ { … } 初期化⽂ (the init statement) 条件式 (the condition expression) 後処理⽂ (the post statement) for ⽂は、セミコロン(;)によって、以下の3つの部分に分かれている for ループの処理(下記では「…」のところ)が 終わった後に実⾏する処理
  29. FOR for i := 0 ; i < 10 ;

    i++ { … } 初期化⽂ (the init statement) 条件式 (the condition expression) 後処理⽂ (the post statement) for ⽂は、セミコロン(;)によって、以下の3つの部分に分かれている 条件式が falseになるまで 繰り返される
  30. FOR for i := 0 ; i < 10 ;

    i++ { … } true false ※上記は正しいフローチャートの 書き⽅ではありません
  31. SWITCH • switch⽂を使うことでIf-else⽂と同等のことを シンプルにかける • switch⽂もfor⽂のように条件式の前に、 初期化⽂を書ける • 他⾔語とは違い、 選択された

    case だけを実⾏して それに続く全ての case は実⾏されない • caseも定数である必要はなく、 関係する値は整数である必要もない
  32. SWITCH EVALUATIONS ORDER ※Go playground上の時間は、 いつも "2009-11-10 23:00:00 UTC" (問題)

    左記が⽰している⽇時は何の⽇でしょう︖ 「Go 1」が リリースされた⽇ Goが公のオープンソース プロジェクトになった⽇ Goという名前がついた⽇ A B C
  33. SWITCH EVALUATIONS ORDER ※Go playground上の時間は、 いつも "2009-11-10 23:00:00 UTC" (問題)

    左記が⽰している⽇時は何の⽇でしょう︖ 「Go 1」が リリースされた⽇ Goが公のオープンソース プロジェクトになった⽇ Goという名前がついた⽇ A B C 2012.03.28 2007.09.25
  34. SWITCH EVALUATIONS ORDER • switch⽂は上から下へcaseを評価する • caseの条件が⼀致すれば、そこで停⽌(⾃動的 にbreak)する ※Go playground上の時間は、

    いつも "2009-11-10 23:00:00 UTC" (答え) Goプロジェクトが 公のオープンソースプロジェクトになった⽇
  35. SWITCH WITH NO CONDITION • 条件のないswitchは、 switch true と書くことと同じ •

    switch⽂を使えば⻑くなりがちな “if-then-else” のつながりをシンプルに表現できる
  36. STACKING DEFERS • defer へ渡した関数が複数ある場合、 その呼び出しは スタック( stack )される •

    呼び出し元の関数が returnするとき、 defer へ渡した関数は LIFO(last-in-first-out) の順番で 実⾏される
  37. STACKING DEFERS fmt.Println(0) main関数 deferスタック領域 i = 0 の時 LIFO(last-in-first-out)

    ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  38. STACKING DEFERS fmt.Println(1) fmt.Println(0) main関数 deferスタック領域 i = 1 の時

    LIFO(last-in-first-out) ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  39. STACKING DEFERS fmt.Println(2) fmt.Println(1) fmt.Println(0) main関数 deferスタック領域 i = 2

    の時 LIFO(last-in-first-out) ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  40. STACKING DEFERS fmt.Println(9) … fmt.Println(2) fmt.Println(1) fmt.Println(0) main関数 deferスタック領域 i

    = 9 の時 LIFO(last-in-first-out) ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  41. STACKING DEFERS fmt.Println(9) … fmt.Println(2) fmt.Println(1) fmt.Println(0) main関数 deferスタック領域 main関数終了時

    Call LIFO(last-in-first-out) ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  42. STACKING DEFERS … fmt.Println(2) fmt.Println(1) fmt.Println(0) main関数 deferスタック領域 main関数終了時 Call

    … LIFO(last-in-first-out) ※プロダクトコードでfor文内でdeferはアンチパターンなので注意
  43. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    42 0x00414024 2701 … … &(アドレス演算⼦)でメモリアドレスを取得 出⼒
  44. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    42 0x00414024 2701 … … pの型は*int型 出⼒ int型のポインタ
  45. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    42 0x00414024 2701 … … pの型は*int型 出⼒ ゼロ値は nil が宣⾔される
  46. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    42 0x00414024 2701 … … *pでpに格納されたアドレスを参照し、 参照先の値を取得する 出⼒ 42
  47. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    21 0x00414024 2701 … … *pでpに格納されたアドレス先に 値を格納する 出⼒ 42
  48. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414020 … … 0x00414020

    21 0x00414024 2701 … … *pでpに格納されたアドレス先に 値を格納する 出⼒ 42 間接参照(dereferencingまたはindirecting)
  49. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414024 … … 0x00414020

    21 0x00414024 2701 … … 出⼒ 42 21 &(アドレス演算⼦)でメモリアドレスを取得
  50. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414024 … … 0x00414020

    21 0x00414024 2701 … … 出⼒ 42 21 *pでpに格納されたアドレス先から 値(2701)を参照する
  51. POINTERS メモリアドレス 値 … … 0x0040C140 0x00414024 … … 0x00414020

    21 0x00414024 73 … … 出⼒ 42 21 2701÷37をした結果得た「73」を 参照先に格納する
  52. POINTERS TO STRUCTS 構造体のフィールドは、 構造体ポインタ越しにアクセスできる ポインタの知識を使えば、 構造体の X フィールドに、 構造体ポインタ

    p でアクセスする時 (*p).X と記述する しかし、この記述は⾯倒なため、 代わりに露⾻な参照なしの p.X と書くことも認められている
  53. SLICES コロンで区切られた⼆つのインデックス low と high で 境界を指定することによりスライスが形成される a[low : high]

    この例の場合、 primesからインデックス1からインデックス4までをスライ スとするため、sは以下のようになる [3 5 7]
  54. スライスはどんなデータも格納しておらず、 単に元の配列の部分列を指し⽰している メモリアドレス 値 0x004C0000 “John” 0x004C0004 “Paul” 0x004C0008 “George”

    0x004C000C “Ringo” ※説明をイメージしてもらうためにメモリマップを書いているが、実際とは異なる。 names
  55. スライスはどんなデータも格納しておらず、 単に元の配列の部分列を指し⽰している メモリアドレス 値 0x004C0000 “John” 0x004C0004 “Paul” 0x004C0008 “George”

    0x004C000C “Ringo” ※説明をイメージしてもらうためにメモリマップを書いているが、実際とは異なる。 names フィールド 値 array 0x004C0000 len 2 cap 4 a
  56. スライスはどんなデータも格納しておらず、 単に元の配列の部分列を指し⽰している メモリアドレス 値 0x004C0000 “John” 0x004C0004 “Paul” 0x004C0008 “George”

    0x004C000C “Ringo” ※説明をイメージしてもらうためにメモリマップを書いているが、実際とは異なる。 names フィールド 値 array 0x004C0000 len 2 cap 4 フィールド 値 array 0x004C0004 len 2 cap 3 a b
  57. スライスはどんなデータも格納しておらず、 単に元の配列の部分列を指し⽰している メモリアドレス 値 0x004C0000 “John” 0x004C0004 “XXX” 0x004C0008 “George”

    0x004C000C “Ringo” ※説明をイメージしてもらうためにメモリマップを書いているが、実際とは異なる。 names フィールド 値 array 0x004C0000 len 2 cap 4 フィールド 値 array 0x004C0004 len 2 cap 3 a b
  58. SLICE LITERALS q := []int{2, 3, 5, 7, 11, 13}

    上記はまず、 [6]int{2, 3, 5, 7, 11, 13} という配列ができ、 それを参照するスライスが 作成され、 qに初期化⼦として定義される
  59. SLICE DEFAULTS メモリアドレス 値 0x00456000 2 0x00456004 3 0x00456008 5

    0x0045600C 7 0x00456010 11 0x00456014 13 フィールド 値 array 0x00456000 len 6 cap 6 orignal s 出⼒
  60. SLICE DEFAULTS メモリアドレス 値 0x00456000 2 0x00456004 3 0x00456008 5

    0x0045600C 7 0x00456010 11 0x00456014 13 フィールド 値 array 0x00456004 len 3 cap 5 orignal s 出⼒ [3 5 7]
  61. SLICE DEFAULTS メモリアドレス 値 0x00456000 2 0x00456004 3 0x00456008 5

    0x0045600C 7 0x00456010 11 0x00456014 13 フィールド 値 array 0x00456004 len 2 cap 5 orignal s 出⼒ [3 5 7] [3 5]
  62. SLICE DEFAULTS メモリアドレス 値 0x00456000 2 0x00456004 3 0x00456008 5

    0x0045600C 7 0x00456010 11 0x00456014 13 フィールド 値 array 0x00456008 len 1 cap 4 orignal s 出⼒ [3 5 7] [3 5] [5]
  63. フィールド 値 array 0x00456000 len 5 cap 5 a 出⼒

    a len=5 cap=5 [0 0 0 0 0] メモリアドレス 値 0x00456000 0 0x00456004 0 0x00456008 0 0x0045600C 0 0x00456010 0 a orignal
  64. フィールド 値 array 0x00456040 len 0 cap 5 b 出⼒

    a len=5 cap=5 [0 0 0 0 0] b len=0 cap=5 [] b orignal メモリアドレス 値 0x00456040 0 0x00456044 0 0x00456048 0 0x0045604C 0 0x00456050 0
  65. 出⼒ a len=5 cap=5 [0 0 0 0 0] b

    len=0 cap=5 [] c len=2 cap=5 [0 0] フィールド 値 array 0x00456040 len 0 cap 5 b b orignal メモリアドレス 値 0x00456040 0 0x00456044 0 0x00456048 0 0x0045604C 0 0x00456050 0 フィールド 値 array 0x00456040 len 2 cap 5 c
  66. 出⼒ a len=5 cap=5 [0 0 0 0 0] b

    len=0 cap=5 [] c len=2 cap=5 [0 0] d len=3 cap=3 [0 0 0] フィールド 値 array 0x00456040 len 0 cap 5 b b orignal メモリアドレス 値 0x00456040 0 0x00456044 0 0x00456048 0 0x0045604C 0 0x00456050 0 フィールド 値 array 0x00456040 len 2 cap 5 c フィールド 値 array 0x00456048 len 3 cap 3 d
  67. フィールド 値 array 0x00414028 len 1 cap 2 s メモリアドレス

    値 0x00414028 0 0x0041402C 0 s orignal 出⼒ len=0 cap=0 [] len=1 cap=2 [0] 容量が不⾜しているため、 新たに配列が割り当てられた
  68. フィールド 値 array 0x00414028 len 1 cap 2 s メモリアドレス

    値 0x00414028 0 0x0041402C 0 s orignal 出⼒ len=0 cap=0 [] len=1 cap=2 [0] 容量が不⾜しているため、 新たに配列が割り当てられた 新たに割り当てられる容量は、 おおよそ2倍ずつ確保される
  69. フィールド 値 array 0x00414028 len 1 cap 2 s メモリアドレス

    値 0x00414028 0 0x0041402C 0 s orignal 出⼒ len=0 cap=0 [] len=1 cap=2 [0] 容量が不⾜しているため、 新たに配列が割り当てられた 新たに割り当てられる容量は、 おおよそ2倍ずつ確保される 「TCMalloc (Thread-Caching Malloc)」 というアルゴリズムを使って、高速に動的メモリを確保している TCMallocについての参考: Google が公開しているソフトウェアの解説(その4)- Performance tools - (https://japan.googleblog.com/2009/05/google-4-performance- tools.html) の後半でTCMallocについて説明されている
  70. フィールド 値 array 0x00414028 len 2 cap 2 s メモリアドレス

    値 0x00414028 0 0x0041402C 1 s orignal 出⼒ len=0 cap=0 [] len=1 cap=2 [0] len=2 cap=2 [0 1] 容量があるため、 スライスし直されて 値がセットされた
  71. フィールド 値 array 0x0045E020 len 5 cap 8 s メモリアドレス

    値 0x0045E020 0 0x0045E024 1 0x0045E028 2 0x0045E02C 3 0x0045E030 4 s orignal 出⼒ len=0 cap=0 [] len=1 cap=2 [0] len=2 cap=2 [0 1] len=5 cap=8 [0 1 2 3 4] 容量が不⾜しているため、 新たに配列が割り当てられた
  72. RANGE CONTINUED インデックスだけ取得する場合 または for i, _ := range pow

    要素だけ取得する場合 for _, v := range pow for i := range pow
  73. MAPS map はキーと値とを関連付ける make 関数は指定された型の マップを初期化し、 使⽤可能な状態で返す マップのゼロ値は nil nil

    マップはキーがなく、 またキーを追加することもできない 詳細は、以下のURL先を参照。 https://blog.golang.org/go-maps-in-action https://github.com/golang/go/blob/master/src/runtime/map.go
  74. MUTATING MAPS 要素(elem)の挿⼊や更新: m[key] = elem 要素の取得: elem = m[key]

    要素の削除: delete(m, key) キーに対する要素が存在するかどうかは、2つめの値で確認する: elem, ok = m[key] ok はキーが存在しる場合は true 、存在しない場合は false となる mapに key が存在しない場合、 elem はmapの要素の型のゼロ値となる
  75. pos neg func(x int) int { sum += x return

    sum } func(x int) int { sum += x return sum } sum int sum int 出⼒ 0 0 1 -2 3 -6 6 -12 10 -20 15 -30 21 -42 28 -56 36 -72 45 -90
  76. ⼀緒に読むと良い記事 • Go⾔語の初⼼者が⾒ると幸せになれる場所 #golang (https://qiita.com/tenntenn/items/0e33a4959250d1a55045) • 他⾔語プログラマがgolangの基本を押さえる為のまとめ (https://qiita.com/tfrcm/items/e2a3d7ce7ab8868e37f7) • 実装して理解するスライス

    #golang (https://qiita.com/tenntenn/items/5229bce80ddb688a708a) • Goを学びたての⼈が誤解しがちなtypeと構造体について #golang (https://qiita.com/tenntenn/items/45c568d43e950292bc31) • ゼロ値を使おう #golang (https://qiita.com/tenntenn/items/c55095585af64ca28ab5) • Goのスコープについて考えてみよう #golang (https://qiita.com/tenntenn/items/ac5940dfbca703183fdf) • STRING と RUNE (https://text.baldanders.info/golang/string-and-rune/)
  77. ⼀緒に読むと良い記事 • 忘れがちなGo⾔語の書式指定⼦を例付きでまとめた (https://qiita.com/Sekky0905/items/c9cbda2498a685517ad0) • Go⾔語 if⽂のサンプル (https://itsakura.com/golang-if#s1) • エキスパートGo

    (https://www.slideshare.net/takuyaueda967/go-77689475) • Goのnil,true,falseは変数名に使えるという話 (https://shogo82148.github.io/blog/2018/11/22/go-nil/) • Goのスライス容量拡張量がどのように決まるのか追った / 180713 LT (https://speakerdeck.com/kaznishi/180713-lt) • goimportsを使ってIntellij IDEAでGoのコードのimportを⼿軽に整理する (https://qiita.com/dmnlk/items/c423d5853cc129ab77a4) • Goの定数の話 (https://qiita.com/hkurokawa/items/a4d402d3182dff387674)
  78. THANKS • A Tour of Go (http://tour.golang.org/) • A Tour

    of Go (⽇本語翻訳版) (https://go-tour-jp.appspot.com) • gopherize.me (https://gopherize.me/) • egonelbre/gophers (https://github.com/egonelbre/gophers)