データファイルを読んで表示する - Scheme VM を書く

基本機能として open-input-file, read, close-input-por を実装する。
補助機能として call-with-input-file もライブラリとして実装しておけばすこしはきれいに。

ついでに

  • HTTP の レスポンスヘッダを出力する処理を分ける
  • HTML を出力する(Gauche の html-lite.scm 的なものはあとで考える)

をやった。

(define (main)
  (print (http:header))
  (print "<html><head></head><body><p>")
  (call-with-input-file "/home/taro/vm/wiki-data.scm"
    (lambda (p)
      (print (read p))))
  (print "</p></body></html>"))

(define (http:header)
  "Status: 200 OK
Content-type: text/html\n")

(define (call-with-input-file file proc)
  (let* ([port (open-input-file file)]
         [ret (proc port)])
    (close-input-port port)
    ret))

(define (print s)
  (display s)
  (display "\n"))

(main)