2010/07/03


ゴッ...ゴホンゴホン...
Go Programming [Paperback]
Go Programming [Paperback]
John P. Baugh (Author)
No customer reviews yet. Be the first.
Price: $19.99 & eligible for FREE Super Saver Shipping on orders over $25. Details
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.
Want it delivered Tuesday, July 6? Order it in the next 0 hours and 37 minutes, and choose One-Day Shipping at checkout. Details
3 new from $19.24


サイトはここ。
Go Programming

Welcome to the official website accompanying the book, Go Programming . The book can be purchased fr...

http://www.goprogrammingbook.com/
twitterアカウントはここ。さっきfollowされて気づいた。
Posted at by



2010/06/25


GoはJavascriptに似た書き方が出来るのだけど、それを利用して何か書けないかなーと思って、cho45さんのJSDeferred書いてみた。
これを使うと、JSDeferredに似た事が出来る。
cho45.stfuawsc.com

JSDeferredSimple and clean asynchronous processing.SampleJSDeferred SamplesDownloadjsdeferred.jsNo c...

http://cho45.stfuawsc.com/jsdeferred/
サンプルだとこんな感じ。 package main

import . "deferred"
import "syscall"
import "http"
import "xml"
import "os"

type feed struct {
    Entry []struct {
        Title string
        Link []struct {
            Rel  string "attr"
            Href string "attr"
        }
        Summary string
    }
}

func main() {
    Deferred().
        Next(func() string {
            return "「この戻り値が...」"
        }).
        Next(func(v string) {
            println("ここの引数にくる!:" + v);
        }).
        Next(func() {
            println("かけっこすものよっといで!");
        }).
        Loop(3, func(i int) {
            println(string("ABC"[i]) + ":はい!");
        }).
        Next(func() {
            println("位置についてよーいどん!");
        }).
        Parallel([]interface{} {
            func() {
                println("A:一番手だしちょっと昼寝してから行くか");
                syscall.Sleep(1000*1000*300);
                println("A:ちょwww");
            },
            func() {
                syscall.Sleep(1000*1000*200);
                println("B:たぶん2位かな?");
            },
            func() {
                syscall.Sleep(1000*1000*100);
                println("C:俺いっちばーん!");
            },
        }).
        Next(func() {
            println("しゅーりょー!");
        }).
        Next(func() {
            println("otsune:ネットウォッチでもするか!");
        }).
        HttpGet("http://b.hatena.ne.jp/otsune/atomfeed").
        Next(func(res *http.Response) *feed {
            var f feed;
            xml.Unmarshal(res.Body, &f);
            return &f
        }).
        Next(func(f *feed) {
            for _, entry := range f.Entry {
                println(entry.Title + "\n\t" + entry.Link[0].Href);
            }
        }).
        HttpGet("http://b.hatena.ne.otsune/"). // this make error
        Next(func(res *http.Response) {
            println("ここにはこないよ");
        }).
        Error(func(err *os.Error) {
            println("これはひどい");
        })
}
Goでは例外がcatch出来ない(そもそもthrowがない)のだけど、Goの風習で戻り値の最後にos.Errorを返す風習があるので、その場合はErrorに飛ばす様にしてある。
mattn's godeferred at master - GitHub

port of jsdeferred: http://cho45.stfuawsc.com/jsdeferred

http://github.com/mattn/godeferred
使い道あるか分かんないけど、とりあえず...
※あんましJSDeferredの仕様詳しく無いので正しい動きじゃないかも苦笑
Posted at by



2010/06/18


ゴホンゴホン!

Miek - Thoughts on (technical) stuff - miek.nl

I'm writing a book about Go. Itis very much a work-in-progress, but I just wanted to mention thiswor...

http://www.miek.nl/blog/archives/2010/05/14/go_book/index.html
PDFで読めるよ。
go-book
Posted at by