Gaucheで実装した継続サーバ

Gaucheで実装した継続サーバを公開した。
http://www.shiro.dreamhost.com/scheme/wiliki/wiliki.cgi?gemma%3a%e7%b6%99%e7%b6%9a%e3%82%b5%e3%83%bc%e3%83%90

継続サーバの面白い動きを知るには、Seasideの動画をみるのが早い。
http://www.seaside.st/Videos/

継続サーバを使うと、CGIリクエストとレスポンスの流れを、より自然に書き下せるので、Webアプリの開発がすばやくなる。
scanfのようにブラウザからの入力を読んで、
printfのようにブラウザに結果のページを返すことができる。

足し算をするCGIのコードは、こんなふうになる。

  (let* ((a (cgi-get-parameter "value"
                               (show (html:html
                                      (html:body
                                       (html:p "? + ? = ?")
                                       (html:p "input number")
                                       (html:form
                                        :method "GET" :action "./cont.cgi"
                                        (html:input :type "hidden" :name "gaup-pid" :value gaup-pid)
                                        (html:input :type "hidden" :name "gaup-cont" :value gaup-cont)
                                        (html:input :type "text" :name "value")
                                        (html:input :type "submit")))))
                               :convert x->number))
         (b  (cgi-get-parameter "value"
                                (show (html:html
                                       (html:body
                                        (html:p (format #f "~a + ? = ?" a))
                                        (html:p "input number")
                                        (html:form
                                         :method "GET" :action "./cont.cgi"
                                         (html:input :type "hidden" :name "gaup-pid" :value gaup-pid)
                                         (html:input :type "hidden" :name "gaup-cont" :value gaup-cont)
                                         (html:input :type "text" :name "value")
                                         (html:input :type "submit")))))
                                :convert x->number)))
    (show (html:html
           (html:body
            (html:p (format #f "~a + ~a = ~a" a b (+ a b))))))))

この実装には難点がある。

  • セッション(リクエストにあらず)ごとにプロセスを立ち上げるから重い。
  • プロセスは常駐しっぱなし、ずっと継続を保存してメモリを食う。

先日の日記で書いたような、永続化ができれば、これを解決できると思う。

  • この実装の、fastCGIとの関連性について調べること>自分
  • Seasideは更にMVCモデルをもっている。件の動画にでてくるcounter0,counter1,...,counter5と書くだけで5つの独立したcounterが設置されるというのはすごいと思う。Smalltalk由来の開発環境ももちろんすごい。