アプリケーションサーバフレームワーク Kahua
柴田 知久
Time Intermedia
特徴
[any material that should appear in print but not on the slide]
継続ベースって?
- 継続とは「これから行われるであろう計算をパッケージ化したもの」
- Scheme(Gauche)は継続を第一級の計算対象として扱える
- 継続はすきな時に呼び出せる
- リンクやフォームが押されたら継続を呼び出す
- ページの状態は継続が保持してる
[any material that should appear in print but not on the slide]
Webアプリケーションのつらいところ
- ページセントリック
- ページの数に比例してテンプレート・ロジックファイルが増える
- ページ間の状態受け渡しを明示的に書いている
- request.set('name',name)
name = request.get('name')とか
- ページ遷移をそれぞれのページに書いている
- リクエストとレスポンスを,連続したページ遷移の一部として考えなければならない
[any material that should appear in print but not on the slide]
Webアプリケーションのつらいところ
- ページ遷移を変更する場合,複数のファイルを修正しなければならない
- ブラウザのバックボタンやウィンドウ複製で動作があやしくなる
- HTML
- テンプレートの30%ぐらいがタグになってしまう
- <, >, / は指がつりそうな場所にある.しかも並んでる.
- タグ単位での入れ替え・切取リ・貼り付けとかめんどう
[any material that should appear in print but not on the slide]
Kahuaでは
< html>
< body>
< h1 valign="center">Hello< /h1>
< /body>
< /html>
を
(html:
(body:
(h1: (@: (valign "center")
"Hello"))))
と書ける.
[any material that should appear in print but not on the slide]
Kahuaでは
(table:
(map:
(lambda (y)
(tr:
(map:
(lambda (x)
(td: (x->s (* x y))))
(iota 9 1))))
(iota 9 1)))
で九九の表を生成.
[any material that should appear in print but not on the slide]
Kahuaでは
(define (edit-page page)
(define save
(entry-lambda (:keyword content)
(set! (ref page 'content) content)
(save-page page)))
(form/cont: (@@: (cont save (content)))
(textarea: (@: (name "content")))
(submit:)))
- フォームがサブミットされたら,form/cont:(フォーム)のcont属性に指定した
手続を呼び出す.
[any material that should appear in print but not on the slide]
Kahuaでは
- 手続に継続を渡す事で次にやることを指定する(CPS)
;; succ failが継続
(define (div/cps x y succ fail)
(if (= y 0)
(fail "error: divide by zero")
(succ (/ x y))))
(define (cps)
(form/cont:
(@@: (cont
(entry-lambda (:keyword x y)
(div/cps (string->number x) (string->number y)
(lambda (sum)
(main-page (h1: (format "~a" sum))))
(lambda (msg)
(error-page (span: msg)))))))
(input-text "x")
(input-text "y")
(submit:)))
[any material that should appear in print but not on the slide]
Kahuaでは
(define-entry (sum)
(main-page
(h1: "sum is")
(number->string
(+ (read-input "first number")
(read-input "second number")))))
(read-input "first number")を評価している時の継続は…
(lambda (n)
(main-page
(h1: "sum is")
(number->string
(+ n
(read-input "second number")))))
[any material that should appear in print but not on the slide]
Kahuaでは
(define (read-input label)
(call/pc (lambda (pcont)
(main-page
(h1: label)
(form/cont:
(@@: (cont (entry-lambda (:keyword input)
(pcont (string->number input)))))
(input: (@: (type "text") (name "input")))
" "
(input: (@: (type "submit") (value "Submit"))))))))
フォームをサブミットすると,捕まえた部分継続を入力値と共に呼び出す
[any material that should appear in print but not on the slide]
続きは…
[any material that should appear in print but not on the slide]