SlideShare a Scribd company logo
10〜30分で何となく分かるGo
#moriyoshi
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
$ export GOROOT=$HOME/go
$ export GOBIN=$HOME/go/bin
$ export GOOS=linux darwin
$ export GOARCH=amd64 x86
$ export PATH=$GOBIN:$PATH
$ mkdir -p $GOBIN
$ hg clone -r release 
  https://go.googlecode.com/hg/ $GOROOT
$ cd $GOROOT/src
$ ./all.bash
package main
import "fmt"

func main() {
    fmt.Printf("   !");
}
$ export GOROOT=$HOME/go
$ export GOBIN=$HOME/go/bin
$ export GOOS=linux
$ export GOARCH=amd64
$ export PATH=$GOBIN:$PATH
$ 6g test.go
$ 6l -o test test.6
$ ./test
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
?
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
package main
import "fmt"

func main() {
    str := "       ";
    str += "   ";
    fmt.Printf("%sn", str);
}
package main
import "fmt"

func main() {
    arr := [4]int { 1, 2,   3, 4};
    fmt.Printf("0: %dn",   arr[0]);
    fmt.Printf("1: %dn",   arr[1]);
    fmt.Printf("2: %dn",   arr[2]);
    fmt.Printf("3: %dn",   arr[3]);
}
package main
import "fmt"

func main() {
    str1 := "Hello, world!";
    str2 := "        ,     ";
    fmt.Printf("%s (%d)n", str1, len(str1));
    fmt.Printf("%sn", str1[0:5]);
    fmt.Printf("%s (%d)n", str2, len(str2));
    fmt.Printf("%sn", str2[0:5]); // WTF!
}
package main
import "fmt"
import "utf8"

func main() {
    str1 := "Hello, world!";
    str2 := "        ,     ";
    fmt.Printf("%s (%d)n", str1, len(str1));
    fmt.Printf("%sn", str1[0:5]);
    fmt.Printf("%s (%d)n", str2,
               utf8.RuneCountInString(str2));
    // FIXME: utf8     substring
}
package main
import "fmt"

func main() {
    str := "Hello";

    for i, c := range str {
        fmt.Printf("%d: %cn", i, c);
    }
}
package main
import "fmt"

func main() {
    str := "Hello";

    for i := 0; i < len(str); i += 1 {
        fmt.Printf("> %cn", str[i]);
    }
}
package main
import "fmt"

func main() {
    str := "Hello";

    i := 0;
    for {
        if i >= len(str) {
            break
        }
        fmt.Printf("> %cn", str[i]);
        i += 1;
    }
}
package main
import "bufio"
import "os"
import "fmt"

func main() {
    in := bufio.NewReader(os.Stdin);

    for {
        str, e := in.ReadString('n');
        if e != nil {
            if e != os.EOF {
                fmt.Printf("Error: %sn", e);
            }
            break
        }
        os.Stdout.WriteString("-> ");
        os.Stdout.WriteString(str);
    }
}
package main
import "fmt"
import "regexp"

func main() {
    re, e := regexp.Compile("[A-Z][a-z]+");
    if e != nil {
        fmt.Printf("Error: %sn", e);
        return
    }
    fmt.Printf("%tn", re.MatchString("test"));
    matches := re.MatchStrings("Abc Def ");
    for i := range matches {
        fmt.Printf("%sn", matches[i]);
    }
    str := "test Test abc";
    fmt.Printf("%sn", re.ReplaceAllString(str , "***"));
}
package main
import (
    "io";
    "fmt";
    "http"
)

func main() {
    url := "http://search.twitter.com/search.json?q="
            + http.URLEscape("#moriyoshi");
    resp, _, e := http.Get(url);
    if e != nil { goto Error; }
    body, e := io.ReadAll(resp.Body);
    if e != nil { goto Error; }
    resp.Body.Close();
    fmt.Printf(">>> %sn", string(body));
    return;

Error:
    fmt.Printf("Error: %sn", e);
    return;
}
package main
import (
    "io";
    "fmt";
    "http";
    "json";
)

func jsonGet(url string) json.Json {
    resp, _, e := http.Get(url);
    if e != nil { goto Error; }
    body, e := io.ReadAll(resp.Body);
    if e != nil { goto Error; }
    resp.Body.Close();
    jsonObj, ok, etok := json.StringToJson(string(body));
    if !ok {
        fmt.Printf("JSON syntax error near: " + etok);
        return nil;
    }
    return jsonObj;
Error:
    fmt.Printf("Error: %sn", e);
    return nil;
}
func main() {
    url := "http://search.twitter.com/search.json?q="
            + http.URLEscape("#moriyoshi");
    j := jsonGet(url);
    results := json.Walk(j, "results");
    for i := 0; i < results.Len(); i += 1 {
        r := results.Elem(i);
        fmt.Printf("%s: %sn",
                    r.Get("from_user"),
                    r.Get("text"));
    }
    return;
}
package main
import (
    "fmt";
    "time";
)

func sub(n int) {
    fmt.Printf("Goroutine #%d started.n", n);
    for i := 0; i < 5; i += 1 {
        fmt.Printf("%d: %dn", n, i);
        time.Sleep(1e9);
    }
}

func main() {
    for i := 0; i < 10; i += 1 {
        go sub(i);
    }
    time.Sleep(5e9);
}
package main
import (
    "fmt";
    "time";
)

func sub(n int, ch chan int) {
    fmt.Printf("Goroutine #%d started.n",
n);
    for i := 0; i < 5; i += 1 {
        fmt.Printf("%d: %dn", n, i);
        time.Sleep(1e8);
    }
    ch <- n
}
func main() {
    ch := make(chan int);
    for n := 0; n < 10; n += 1 {
        go sub(n, ch);
        time.Sleep(4e8)
    }
    for i := 0; i < 10; i += 1 {
        n := <- ch;
        fmt.Printf("Goroutine #%d ended.
n", n)
    }
}
package main
import (
    "fmt";
)
type Employee struct {
    name string;
}
type Company struct {
    name string;
    employees []Employee;
}

func main() {
    c := Company { name:"Acme" };
    c.employees = []Employee {
       Employee { name:"Foo" },
       Employee { name:"Bar" }
    };

    fmt.Printf("Company name: %sn", c.name);
    fmt.Printf("Employees: %dn", len(c.employees));
    for _, employee := range c.employees {
        fmt.Printf("    %sn", employee.name);
    }
}
package main
import (
    "fmt";
)

func main() {
    m := make(map[string] string);
    m["Foo"] = "Hoge";
    m["Bar"] = "Fuga";
    for k, v := range m {
        fmt.Printf("%s: %sn", k, v)
    }
}
package main
import (
    "fmt";
)
type MyInt int;
type Foo struct {
    values []int;
}

func (self *Foo) sum() int {
    retval := 0;
    for _, v := range self.values {
        retval += v
    }
    return retval
}

func main() {
    f := &Foo { values: []int { 0, 1, 2, 3, 4 } };
    fmt.Printf("%dn", f.sum());
}
package main
import (
    "fmt";
)
type MyInt int;

func (self MyInt) add(rhs int) MyInt {
    return MyInt(int(self) + rhs)
}

func main() {
    fmt.Printf("%dn",
               MyInt(1).add(4).add(5));
}
package main
import (
    "fmt"
)

type IHello interface {
    sayHello()
}

type IKonnichiwa interface {
    sayKonnichiwa()
}

type IBilingual interface {
    IHello;
    IKonnichiwa
}
type TypeA int;
type TypeB int;
type TypeC int;

func (_ TypeA) sayHello() {}

func (_ TypeB) sayKonnichiwa() {}

func (_ TypeC) sayHello() {}

func (_ TypeC) sayKonnichiwa() {}

func hello(_ IHello) {
    fmt.Printf("Hellon")
}
func konnichiwa(_ IKonnichiwa) {
    fmt.Printf("Konnichiwan")
}
func main() {
    var (
        a TypeA;
        b TypeB;
        c TypeC
    );

    hello(a);
    konnichiwa(b);
    hello(c);
    konnichiwa(c);
}
package main

type Foo struct {
    a int
}
type Bar struct {
    b int
}
type FuBar struct {
    *Foo;
    *Bar
}
func (_ *Foo) doSomething() {}

func (_ *Bar) doIt() {}

func main() {
    fubar := new(FuBar);
    fubar.doSomething();
    fubar.doIt()
}
package main

import "fmt";

func main() {
    fmt.Printf("%dn",
        func(f func(func(int) int) int) int {
            return f(func(a int) int { return a + 2 })
        }(func(g func(int) int) int { return g(1) }));
}
package main
import "fmt"

type UntypedFunc func(Any) Any;
type Any struct {
    UntypedFunc;
    int
}

func main() {
    // Y-combinator
    result := func(f Any) Any {
        return func(x Any) Any {
            return f.UntypedFunc(
                Any{ UntypedFunc: func(y Any) Any {
                    return x.UntypedFunc(x).UntypedFunc(y)
                } } )
        }(
            Any{ UntypedFunc: func(x Any) Any {
                return f.UntypedFunc(
                    Any{ UntypedFunc: func(y Any) Any {
                        return x.UntypedFunc(x).UntypedFunc(y)
                    } } )
            } }
        );
    }(Any{ UntypedFunc: func(f Any) Any {
        return Any{ UntypedFunc: func(n Any) Any {
            if (n.int == 0) {
                return Any{ int: 1 }
            }
            return Any{ int: f.UntypedFunc(Any{ int: n.int - 1 }).int * n.int }
        } }
    } } );
    fmt.Printf("%dn", result.UntypedFunc(Any{ int: 5 }).int);
}
package main

import "fmt";

func sliceInfo(arr []int) {
    fmt.Printf("len(arr)=%dn", len(arr));
    fmt.Printf("cap(arr)=%dn", cap(arr));
}

func arrayInfo(arr *[4]int) {
    fmt.Printf("len(arr)=%dn", len(arr));
    fmt.Printf("cap(arr)=%dn", cap(arr));
}

func main() {
    arr := [4]int { 1, 2, 3, 4 };
    arrayInfo(&arr);
    // doesn't compile
    // sliceInfo(arr);
    sliceInfo(&arr);
    // doesn't compile
    // arrayInfo(arr[0:2]);
    sliceInfo(arr[0:2])
}
10〜30分で何となく分かるGo
Ad

More Related Content

What's hot (19)

북스터디 디스커버리 Go 언어
북스터디 디스커버리 Go 언어북스터디 디스커버리 Go 언어
북스터디 디스커버리 Go 언어
동규 이
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
領一 和泉田
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Going Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoGoing Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google Go
Eleanor McHugh
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
bhaktisagar4
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
6. function
6. function6. function
6. function
웅식 전
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
njpst8
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
Mahmoud Samir Fayed
 
Program presentation
Program presentationProgram presentation
Program presentation
MdAlauddinRidoy
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88
Mahmoud Samir Fayed
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
Function work in JavaScript
Function work in JavaScriptFunction work in JavaScript
Function work in JavaScript
Rhio Kim
 
북스터디 디스커버리 Go 언어
북스터디 디스커버리 Go 언어북스터디 디스커버리 Go 언어
북스터디 디스커버리 Go 언어
동규 이
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Going Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoGoing Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google Go
Eleanor McHugh
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
bhaktisagar4
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
Double linked list
Double linked listDouble linked list
Double linked list
Sayantan Sur
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
njpst8
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88
Mahmoud Samir Fayed
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
Function work in JavaScript
Function work in JavaScriptFunction work in JavaScript
Function work in JavaScript
Rhio Kim
 

Viewers also liked (6)

顧客価値って奥深いですね
顧客価値って奥深いですね顧客価値って奥深いですね
顧客価値って奥深いですね
Takuya Kawabe
 
going loopy - adventures in iteration with google go
going loopy - adventures in iteration with google gogoing loopy - adventures in iteration with google go
going loopy - adventures in iteration with google go
Eleanor McHugh
 
PHP7を魔改造した話
PHP7を魔改造した話PHP7を魔改造した話
PHP7を魔改造した話
Moriyoshi Koizumi
 
なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?
Yoshitaka Kawashima
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
bcoca
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
Sarah Z
 
顧客価値って奥深いですね
顧客価値って奥深いですね顧客価値って奥深いですね
顧客価値って奥深いですね
Takuya Kawabe
 
going loopy - adventures in iteration with google go
going loopy - adventures in iteration with google gogoing loopy - adventures in iteration with google go
going loopy - adventures in iteration with google go
Eleanor McHugh
 
なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?なぜデータモデリングが重要なのか?
なぜデータモデリングが重要なのか?
Yoshitaka Kawashima
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
bcoca
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
Sarah Z
 
Ad

Similar to 10〜30分で何となく分かるGo (20)

An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
Eleanor McHugh
 
Hello Go
Hello GoHello Go
Hello Go
Eleanor McHugh
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
Hean Hong Leong
 
Introduction to Go for Java Programmers
Introduction to Go for Java ProgrammersIntroduction to Go for Java Programmers
Introduction to Go for Java Programmers
Kalpa Pathum Welivitigoda
 
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
Codemotion
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
 
Function & Recursion in C
Function & Recursion in CFunction & Recursion in C
Function & Recursion in C
Aditya Nihal Kumar Singh
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
Eleanor McHugh
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
Eleanor McHugh
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
Rupendra Choudhary
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Functions in c
Functions in cFunctions in c
Functions in c
Innovative
 
Cpds lab
Cpds labCpds lab
Cpds lab
praveennallavelly08
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
Robert Stern
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
Anton Arhipov
 
ProgrammingwithGOLang
ProgrammingwithGOLangProgrammingwithGOLang
ProgrammingwithGOLang
Shishir Dwivedi
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
Eleanor McHugh
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
go-lang
 
Go serving: Building server app with go
Go serving: Building server app with goGo serving: Building server app with go
Go serving: Building server app with go
Hean Hong Leong
 
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
going loopy - adventures in iteration with go - Eleanor McHugh - Codemotion M...
Codemotion
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
Eleanor McHugh
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
Eleanor McHugh
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Functions in c
Functions in cFunctions in c
Functions in c
Innovative
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
Robert Stern
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
Jussi Pohjolainen
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
Anton Arhipov
 
Ad

More from Moriyoshi Koizumi (20)

Goをカンストさせる話
Goをカンストさせる話Goをカンストさせる話
Goをカンストさせる話
Moriyoshi Koizumi
 
Authentication, Authorization, OAuth, OpenID Connect and Pyramid
Authentication, Authorization, OAuth, OpenID Connect and PyramidAuthentication, Authorization, OAuth, OpenID Connect and Pyramid
Authentication, Authorization, OAuth, OpenID Connect and Pyramid
Moriyoshi Koizumi
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
HLSについて知っていることを話します
HLSについて知っていることを話しますHLSについて知っていることを話します
HLSについて知っていることを話します
Moriyoshi Koizumi
 
Pyramidのrendererをカスタマイズする
PyramidのrendererをカスタマイズするPyramidのrendererをカスタマイズする
Pyramidのrendererをカスタマイズする
Moriyoshi Koizumi
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 
Uguisudani
UguisudaniUguisudani
Uguisudani
Moriyoshi Koizumi
 
よいことも悪いこともぜんぶPHPが教えてくれた
よいことも悪いこともぜんぶPHPが教えてくれたよいことも悪いこともぜんぶPHPが教えてくれた
よいことも悪いこともぜんぶPHPが教えてくれた
Moriyoshi Koizumi
 
Ik in action
Ik in actionIk in action
Ik in action
Moriyoshi Koizumi
 
mod_himoteからはじめよう
mod_himoteからはじめようmod_himoteからはじめよう
mod_himoteからはじめよう
Moriyoshi Koizumi
 
HPHPは約束の地なのか
HPHPは約束の地なのかHPHPは約束の地なのか
HPHPは約束の地なのか
Moriyoshi Koizumi
 
Phjosh(仮)プロジェクト
Phjosh(仮)プロジェクトPhjosh(仮)プロジェクト
Phjosh(仮)プロジェクト
Moriyoshi Koizumi
 
Goをカンストさせる話
Goをカンストさせる話Goをカンストさせる話
Goをカンストさせる話
Moriyoshi Koizumi
 
Authentication, Authorization, OAuth, OpenID Connect and Pyramid
Authentication, Authorization, OAuth, OpenID Connect and PyramidAuthentication, Authorization, OAuth, OpenID Connect and Pyramid
Authentication, Authorization, OAuth, OpenID Connect and Pyramid
Moriyoshi Koizumi
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
HLSについて知っていることを話します
HLSについて知っていることを話しますHLSについて知っていることを話します
HLSについて知っていることを話します
Moriyoshi Koizumi
 
Pyramidのrendererをカスタマイズする
PyramidのrendererをカスタマイズするPyramidのrendererをカスタマイズする
Pyramidのrendererをカスタマイズする
Moriyoshi Koizumi
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 
よいことも悪いこともぜんぶPHPが教えてくれた
よいことも悪いこともぜんぶPHPが教えてくれたよいことも悪いこともぜんぶPHPが教えてくれた
よいことも悪いこともぜんぶPHPが教えてくれた
Moriyoshi Koizumi
 
mod_himoteからはじめよう
mod_himoteからはじめようmod_himoteからはじめよう
mod_himoteからはじめよう
Moriyoshi Koizumi
 
HPHPは約束の地なのか
HPHPは約束の地なのかHPHPは約束の地なのか
HPHPは約束の地なのか
Moriyoshi Koizumi
 
Phjosh(仮)プロジェクト
Phjosh(仮)プロジェクトPhjosh(仮)プロジェクト
Phjosh(仮)プロジェクト
Moriyoshi Koizumi
 

Recently uploaded (20)

Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
5kW Solar System in India – Cost, Benefits & Subsidy 2025
5kW Solar System in India – Cost, Benefits & Subsidy 20255kW Solar System in India – Cost, Benefits & Subsidy 2025
5kW Solar System in India – Cost, Benefits & Subsidy 2025
Ksquare Energy Pvt. Ltd.
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI PaymentsTrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI Payments
Trs Labs
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and MLGyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
GyrusAI - Broadcasting & Streaming Applications Driven by AI and ML
Gyrus AI
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
5kW Solar System in India – Cost, Benefits & Subsidy 2025
5kW Solar System in India – Cost, Benefits & Subsidy 20255kW Solar System in India – Cost, Benefits & Subsidy 2025
5kW Solar System in India – Cost, Benefits & Subsidy 2025
Ksquare Energy Pvt. Ltd.
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptxWebinar - Top 5 Backup Mistakes MSPs and Businesses Make   .pptx
Webinar - Top 5 Backup Mistakes MSPs and Businesses Make .pptx
MSP360
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI PaymentsTrsLabs - Leverage the Power of UPI Payments
TrsLabs - Leverage the Power of UPI Payments
Trs Labs
 

10〜30分で何となく分かるGo

  • 8. $ export GOROOT=$HOME/go $ export GOBIN=$HOME/go/bin $ export GOOS=linux darwin $ export GOARCH=amd64 x86 $ export PATH=$GOBIN:$PATH $ mkdir -p $GOBIN $ hg clone -r release https://go.googlecode.com/hg/ $GOROOT $ cd $GOROOT/src $ ./all.bash
  • 9. package main import "fmt" func main() { fmt.Printf(" !"); }
  • 10. $ export GOROOT=$HOME/go $ export GOBIN=$HOME/go/bin $ export GOOS=linux $ export GOARCH=amd64 $ export PATH=$GOBIN:$PATH $ 6g test.go $ 6l -o test test.6 $ ./test
  • 13. ?
  • 16. package main import "fmt" func main() { str := " "; str += " "; fmt.Printf("%sn", str); }
  • 17. package main import "fmt" func main() { arr := [4]int { 1, 2, 3, 4}; fmt.Printf("0: %dn", arr[0]); fmt.Printf("1: %dn", arr[1]); fmt.Printf("2: %dn", arr[2]); fmt.Printf("3: %dn", arr[3]); }
  • 18. package main import "fmt" func main() { str1 := "Hello, world!"; str2 := " , "; fmt.Printf("%s (%d)n", str1, len(str1)); fmt.Printf("%sn", str1[0:5]); fmt.Printf("%s (%d)n", str2, len(str2)); fmt.Printf("%sn", str2[0:5]); // WTF! }
  • 19. package main import "fmt" import "utf8" func main() { str1 := "Hello, world!"; str2 := " , "; fmt.Printf("%s (%d)n", str1, len(str1)); fmt.Printf("%sn", str1[0:5]); fmt.Printf("%s (%d)n", str2, utf8.RuneCountInString(str2)); // FIXME: utf8 substring }
  • 20. package main import "fmt" func main() { str := "Hello"; for i, c := range str { fmt.Printf("%d: %cn", i, c); } }
  • 21. package main import "fmt" func main() { str := "Hello"; for i := 0; i < len(str); i += 1 { fmt.Printf("> %cn", str[i]); } }
  • 22. package main import "fmt" func main() { str := "Hello"; i := 0; for { if i >= len(str) { break } fmt.Printf("> %cn", str[i]); i += 1; } }
  • 23. package main import "bufio" import "os" import "fmt" func main() { in := bufio.NewReader(os.Stdin); for { str, e := in.ReadString('n'); if e != nil { if e != os.EOF { fmt.Printf("Error: %sn", e); } break } os.Stdout.WriteString("-> "); os.Stdout.WriteString(str); } }
  • 24. package main import "fmt" import "regexp" func main() { re, e := regexp.Compile("[A-Z][a-z]+"); if e != nil { fmt.Printf("Error: %sn", e); return } fmt.Printf("%tn", re.MatchString("test")); matches := re.MatchStrings("Abc Def "); for i := range matches { fmt.Printf("%sn", matches[i]); } str := "test Test abc"; fmt.Printf("%sn", re.ReplaceAllString(str , "***")); }
  • 25. package main import ( "io"; "fmt"; "http" ) func main() { url := "http://search.twitter.com/search.json?q=" + http.URLEscape("#moriyoshi"); resp, _, e := http.Get(url); if e != nil { goto Error; } body, e := io.ReadAll(resp.Body); if e != nil { goto Error; } resp.Body.Close(); fmt.Printf(">>> %sn", string(body)); return; Error: fmt.Printf("Error: %sn", e); return; }
  • 26. package main import ( "io"; "fmt"; "http"; "json"; ) func jsonGet(url string) json.Json { resp, _, e := http.Get(url); if e != nil { goto Error; } body, e := io.ReadAll(resp.Body); if e != nil { goto Error; } resp.Body.Close(); jsonObj, ok, etok := json.StringToJson(string(body)); if !ok { fmt.Printf("JSON syntax error near: " + etok); return nil; } return jsonObj; Error: fmt.Printf("Error: %sn", e); return nil; }
  • 27. func main() { url := "http://search.twitter.com/search.json?q=" + http.URLEscape("#moriyoshi"); j := jsonGet(url); results := json.Walk(j, "results"); for i := 0; i < results.Len(); i += 1 { r := results.Elem(i); fmt.Printf("%s: %sn", r.Get("from_user"), r.Get("text")); } return; }
  • 28. package main import ( "fmt"; "time"; ) func sub(n int) { fmt.Printf("Goroutine #%d started.n", n); for i := 0; i < 5; i += 1 { fmt.Printf("%d: %dn", n, i); time.Sleep(1e9); } } func main() { for i := 0; i < 10; i += 1 { go sub(i); } time.Sleep(5e9); }
  • 29. package main import ( "fmt"; "time"; ) func sub(n int, ch chan int) { fmt.Printf("Goroutine #%d started.n", n); for i := 0; i < 5; i += 1 { fmt.Printf("%d: %dn", n, i); time.Sleep(1e8); } ch <- n }
  • 30. func main() { ch := make(chan int); for n := 0; n < 10; n += 1 { go sub(n, ch); time.Sleep(4e8) } for i := 0; i < 10; i += 1 { n := <- ch; fmt.Printf("Goroutine #%d ended. n", n) } }
  • 31. package main import ( "fmt"; ) type Employee struct { name string; } type Company struct { name string; employees []Employee; } func main() { c := Company { name:"Acme" }; c.employees = []Employee { Employee { name:"Foo" }, Employee { name:"Bar" } }; fmt.Printf("Company name: %sn", c.name); fmt.Printf("Employees: %dn", len(c.employees)); for _, employee := range c.employees { fmt.Printf(" %sn", employee.name); } }
  • 32. package main import ( "fmt"; ) func main() { m := make(map[string] string); m["Foo"] = "Hoge"; m["Bar"] = "Fuga"; for k, v := range m { fmt.Printf("%s: %sn", k, v) } }
  • 33. package main import ( "fmt"; ) type MyInt int; type Foo struct { values []int; } func (self *Foo) sum() int { retval := 0; for _, v := range self.values { retval += v } return retval } func main() { f := &Foo { values: []int { 0, 1, 2, 3, 4 } }; fmt.Printf("%dn", f.sum()); }
  • 34. package main import ( "fmt"; ) type MyInt int; func (self MyInt) add(rhs int) MyInt { return MyInt(int(self) + rhs) } func main() { fmt.Printf("%dn", MyInt(1).add(4).add(5)); }
  • 35. package main import ( "fmt" ) type IHello interface { sayHello() } type IKonnichiwa interface { sayKonnichiwa() } type IBilingual interface { IHello; IKonnichiwa }
  • 36. type TypeA int; type TypeB int; type TypeC int; func (_ TypeA) sayHello() {} func (_ TypeB) sayKonnichiwa() {} func (_ TypeC) sayHello() {} func (_ TypeC) sayKonnichiwa() {} func hello(_ IHello) { fmt.Printf("Hellon") } func konnichiwa(_ IKonnichiwa) { fmt.Printf("Konnichiwan") }
  • 37. func main() { var ( a TypeA; b TypeB; c TypeC ); hello(a); konnichiwa(b); hello(c); konnichiwa(c); }
  • 38. package main type Foo struct { a int } type Bar struct { b int } type FuBar struct { *Foo; *Bar }
  • 39. func (_ *Foo) doSomething() {} func (_ *Bar) doIt() {} func main() { fubar := new(FuBar); fubar.doSomething(); fubar.doIt() }
  • 40. package main import "fmt"; func main() { fmt.Printf("%dn", func(f func(func(int) int) int) int { return f(func(a int) int { return a + 2 }) }(func(g func(int) int) int { return g(1) })); }
  • 41. package main import "fmt" type UntypedFunc func(Any) Any; type Any struct { UntypedFunc; int } func main() { // Y-combinator result := func(f Any) Any { return func(x Any) Any { return f.UntypedFunc( Any{ UntypedFunc: func(y Any) Any { return x.UntypedFunc(x).UntypedFunc(y) } } ) }( Any{ UntypedFunc: func(x Any) Any { return f.UntypedFunc( Any{ UntypedFunc: func(y Any) Any { return x.UntypedFunc(x).UntypedFunc(y) } } ) } } ); }(Any{ UntypedFunc: func(f Any) Any { return Any{ UntypedFunc: func(n Any) Any { if (n.int == 0) { return Any{ int: 1 } } return Any{ int: f.UntypedFunc(Any{ int: n.int - 1 }).int * n.int } } } } } ); fmt.Printf("%dn", result.UntypedFunc(Any{ int: 5 }).int); }
  • 42. package main import "fmt"; func sliceInfo(arr []int) { fmt.Printf("len(arr)=%dn", len(arr)); fmt.Printf("cap(arr)=%dn", cap(arr)); } func arrayInfo(arr *[4]int) { fmt.Printf("len(arr)=%dn", len(arr)); fmt.Printf("cap(arr)=%dn", cap(arr)); } func main() { arr := [4]int { 1, 2, 3, 4 }; arrayInfo(&arr); // doesn't compile // sliceInfo(arr); sliceInfo(&arr); // doesn't compile // arrayInfo(arr[0:2]); sliceInfo(arr[0:2]) }