programming language/Go
2021.10.01
ํด๋น๊ธ์ ์๋ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๊ธ ์
๋๋ค. Go๋ฅผ ํฅํ ์ฌํ go-tour-ko.appspot.com Pointers package main import "fmt" func main() { i, j := 42, 2701 p := &i // point to i fmt.Println(*p) // read i through the pointer *p = 21 // set i through the pointer fmt.Println(i) // see the new value of i p = &j // point to j *p = *p / 37 // divide j through the pointer fmt.Println(j) // see the new value of j } c์ธ์ด์ ํฌ์ธ..
programming language/Go
2021.09.25
ํด๋น๊ธ์ ์๋ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๊ธ ์
๋๋ค. Go๋ฅผ ํฅํ ์ฌํ go-tour-ko.appspot.com for package main import "fmt" func main() { sum := 0 for i := 0; i < 10; i++ { sum += i } fmt.Println(sum) } ๊ดํธ๊ฐ ์๋ c๋๋ ๋ฌธ๋ฒ์ด ์๋นํ c๋ ์ ์ฌํด์ ํฌ๊ฒ ๋ค๋ฅด์ง ์๊ฒ ์ฌ์ฉํ ์ ์๋๊ฑฐ๊ฐ๋ค. For continued package main import "fmt" func main() { sum := 1 for ; sum < 1000; { sum += sum } fmt.Println(sum) } for๋ฌธ์์ ์ด๊ธฐํ๊ตฌ๋ถ๊ณผ ์ฆ๊ฐ? ๊ตฌ๋ฌธ์ ํ์๊ฐ ์๋๋ค. ์์ ๊ฐ์ ํ์์ผ๋ก๋ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. F..
programming language/Go
2021.09.23
ํด๋น๊ธ์ ์๋ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๊ธ ์
๋๋ค. Go๋ฅผ ํฅํ ์ฌํ go-tour-ko.appspot.com Short variable declarations package main import "fmt" func main() { var i, j int = 1, 2 k := 3 c, python, java := true, false, "no!" fmt.Println(i, j, k, c, python, java) } ํจ์ ๋ด์๊ฒ๋ := ํ์์ผ๋ก type์ ์ง์ ํด์ฃผ์ง์์๋ ๋ณ์ ์ ์ธ์ด ๊ฐ๋ฅํ์ง๋ง ํจ์ ๋ฐ์ ๋ณ์๋ฅผ ์ ์ธํ ๊ฒฝ์ฐ์๋ := ํ์์ด ์ฌ์ฉ ๋ถ๊ฐ๋ฅํ๋ค. Basic types package main import ( "fmt" "math/cmplx" ) var ( ToBe bool = fa..
programming language/Go
2021.09.22
ํด๋น๊ธ์ ์๋ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๊ธ ์
๋๋ค. Go๋ฅผ ํฅํ ์ฌํ go-tour-ko.appspot.com Packages package main import ( "fmt" "math/rand" ) func main() { fmt.Println("My favorite number is", rand.Intn(10)) } ๋ชจ๋ go ํ๋ก๊ทธ๋จ์ packge๋ก ๊ตฌ์ฑ์ด ๋์ด์๋ค. ํ์ฌ ์ฝ๋์์๋ "fmt"์ "math/rand"๋ฅผ ๋ถ๋ฌ์จ ์ํ rnad.Intn(10)์ ๊ฒฝ์ฐ ์คํ๋๋ ํ๊ฒฝ์ด ๋์ผํ๋ฏ๋ก ๊ฐ์ 1์ด๋ผ๋ ๊ฐ์ด ๋ฐํ๋๊ฒ ๋๋ค. ๋ค์ํ ์ซ์๋ฅผ ๋ด๋ณด๋ด๊ธฐ ์ํด์๋ ๋ณํํ๋ ์๋๊ฐ์ ์ฃผ๋ํ์์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋๋ค. (time ๋ฑ) Imports package main import ( "fm..
programming language/Go
2021.09.21
ํด๋น๊ธ์ ์๋ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ ๊ธ ์
๋๋ค. Go๋ฅผ ํฅํ ์ฌํ go-tour-ko.appspot.com Hello package main import "fmt" func main() { fmt.Println("Hello") } go์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ "hello" ์ถ๋ ฅํ๊ธฐ ์ด๋ป๊ฒ ์ฌ์ฉ์ ํ๋๊ฑด์ง ํ๋ฒ ํด๋ด๋ผ ๋ผ๋ ๋ด์ฉ ํด์ ์ ๋ฆฌ time package main import ( "fmt" "time" ) func main() { fmt.Println("Welcome to the playground!") fmt.Println("The time is", time.Now()) } time ํจํค์ง ์๊ฐ์ ํํํ๊ธฐ ์ํ ํจ์๋ค์ ๊ฐ์ง๊ณ ์์ time.Now() ํ์ฌ ์๊ฐ์ ๊ฐ์ ธ์จ๋ค. ํ์๊ฐ ํ์ฌ..
programming language/Go
2021.09.19
package main import "fmt" func main() { fmt.Println("Hello world") } package main ํจํค์ง๋ฅผ ์ ์ธํ๋ ๋ถ๋ถ ํจํค์ง์ ์ด๋ฆ์ด main์ผ๋ก ๋์ด์๋ค๋ฉด ํ๋ก๊ทธ๋จ ์คํ์ ์ํด ์กด์ฌํ๋ ํจํค์ง ํด๋น ์ด๋ฆ์ด main์ด ์๋ ๋ค๋ฅธ์ด๋ฆ์ผ๋ก ๋์ด์๋ค๋ฉด ์คํ์ด ๋ ์ ์๊ณ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ฒ๋ผ ์ฌ์ฉํ๊ฒ ๋ค๋ ์๋ฏธ c ์ธ์ด์ main๊ณผ ๋น์ทํ ๋งฅ๋ฝ import "fmt" fmt๋ผ๋ ๋ผ๋ ๋ชจ๋์ ๋ถ๋ฌ์จ๋ค. python from์ด๋ c์ธ์ด์ include ์ ๋น์ทํ ๋งฅ๋ฝ fmt.Println("Hello world") hello world๋ผ๋ ๋ฌธ์๋ฅผ ์ถ๋ ฅํ๋ค. fmt ์ถ๋ ฅ์๋ ํฌ๊ฒ 3๊ฐ์ง๊ฐ ์กด์ฌ fmt.Print("hello world") fmt.Println("hello ..
programming language/Go
2021.09.19
์ค์น ํ๊ฒฝ ๋งฅ Mac ๐ฅ๏ธ Go ์ค์น ์งํํ๊ธฐ brew install go Go ์ค์น ํ์ธ go version go env "hello world" ์ถ๋ ฅํ๊ธฐ package main import "fmt" func main() { fmt.Println("hello world") } ํ์ผ ์คํ๋ฐฉ๋ฒ go run file_name ์คํ ๊ฒฐ๊ณผ ์คํ ํ์ผ ๋ง๋ค๊ธฐ go build file_name ์คํ ๊ฒฐ๊ณผ