Symptote
August 25, 2014
160

# Go言語の紹介（かなり浅く浅く）(仮)(お盆開け勉強会)

August 25, 2014

## Transcript

2. ### ࣗݾ঺հ ໊લ : ͠Μ΀ͬͱ ೥ྸ : 20 ॴଐ : ߴઐ

ڵຯ : ɹ ɹ਺ֶͰ࢖͏ਤ(άϥϑ౳)ͷ࡞੒

4. ### Goݴޠͬͯʁ Google ͕։ൃͯ͠Δݴޠ γϯϓϧͳߏจͰ଎౓͕଎͍ͷ͕ಛ௃ ฒྻॲཧʹڧ͘ɼ؆୯ʹ࣮૷ग़དྷΔ webΞϓϦέʔγϣϯΛ࡞ΔͨΊͷϥΠϒϥϦ͕Ұഋ ࣈ۟ɾߏจղੳ༻ͷϥΠϒϥϦ΋Ұഋ Ϛείοτ͕ՄѪ͍ʂʂʂʂʂʂʂʂʂʂʂʂʂ ࢀߟจݙ :

http:/ /golang.jp

6. ### Կʹ࢖͑Δʁ WebΞϓϦέʔγϣϯͷ࡞੒ ΠϯλϓϦλɾίϯύΠϥͷ։ൃ ਺஋ܭࢉ etc… ͋ Ε ɼ ଞ ͷ

ݴ ޠ Ͱ ΋ ྑ ͘ ͳ ͍……ʁ

20. ### ࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,

int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) }
21. ### ࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,

int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε
22. ### ࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,

int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε ͜ͷΑ͏ʹGoݴޠͷ Ұ෦ͱͯ͠ݺͼग़ͤΔɽ
23. ### ࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,

int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε ͜ͷΑ͏ʹGoݴޠͷ Ұ෦ͱͯ͠ݺͼग़ͤΔɽ ϥΠϒϥϦ΋ݺ΂Δ
24. ### CݴޠҎ֎Ͱ͸ʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:

-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) }
25. ### CݴޠҎ֎Ͱ͸ʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:

-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) }
26. ### CݴޠҎ֎Ͱ͸ʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:

-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) } gccʹೖ͍ͬͯΕ͹ɼCFLAGS͔Β ௚઀ࢦఆͯ͠΍Ε͹೉ͳ͘։͚Δ
27. ### CݴޠҎ֎Ͱ͸ʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:

-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) } gccʹೖ͍ͬͯΕ͹ɼCFLAGS͔Β ௚઀ࢦఆͯ͠΍Ε͹೉ͳ͘։͚Δ ϩʔυ͍ͨ͠ϥΠϒϥϦ౳΋ಉ͡ ͘LDFLAGSͰࢦఆग़དྷΔ

32. ### ղ͖ํ π = Arctan 0.25. ্ࣜʹ͍ͭͯɼࠨลΛTaylorల։͢Δͱ π = Σ{0.25n /

(2n + 1)}. Answer ࢀߟจݙ : wikipedia-ԁप཰ͷྺ࢙
33. ### ղ͖ํ π = Arctan 0.25. ্ࣜʹ͍ͭͯɼࠨลΛTaylorల։͢Δͱ π = Σ{0.25n /

(2n + 1)}. Answer ࢀߟจݙ : wikipedia-ԁप཰ͷྺ࢙ ඍੵ෼ͱ͔෼͔Βͳ͍ΜͰɼ࣮ݧతʹٻΊ·͢

35. ### ۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include

<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する，省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) }
36. ### ۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include

<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する，省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) } ϓϩηε਺ͷઃఆ
37. ### ۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include

<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する，省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) } ϓϩηε਺ͷઃఆ ฒྻॲཧ෦(ແ໊ؔ਺)