2009/06/28

Linux 環境での Clozure CL で日本語パス名

Linux 環境での Clozure CL で日本語パス名を扱うには次のコードが必要みたい。 Mac と Win はデフォルトで大丈夫そう。

(ccl::set-pathname-encoding-name :utf-8)

2009/06/26

いまさらだけど Clozure CL は Windows でもスレッドが使える

Clozure CL(CCL)なの。いや、以前からそんな話はきいてたんだけど何故かあまり気にしていなかった。いまさらながら、いじってみると確かにスレッドが使える。 Hunchentoot もすんなり動いた。これで簡単に Windows 上で Web サーバがたてられるw

あとは CP932 だけですね♪

おさらいをかねて初期化ファイルを。 c:/Users/ancient/ccl-init.lisp

;;;; -*- lisp -*-

;;; 最適化
#+nil
(declaim (optimize (debug 3) (safety 3) (speed 0) (space 0)
(compilation-speed 3)))

#+nil
(declaim (optimize (debug 0) (safety 0) (speed 3) (space 0)
(compilation-speed 0)))



;;; 文字コード
(setf ccl:*default-external-format*
(ccl:make-external-format :character-encoding :utf-8
:line-termination :dos)
ccl:*default-file-character-encoding* :utf-8
ccl:*default-socket-character-encoding* :utf-8)


;;; asdf
(require :asdf)

;; ~/letter/lib 以下の asd を登録する。
(loop for path in (directory (translate-logical-pathname
"home:letter;lisp;lib;**;*.asd"))
do (let ((pd (pathname-directory path)))
(unless (member "_darcs" pd :test #'equal)
(pushnew (make-pathname :directory pd)
asdf:*central-registry*
:test #'equal))))

;; clbuild
;;(pushnew (translate-logical-pathname "home:letter;lisp;clbuild;systems;")
;; asdf:*central-registry*)
;; ~/letter/lib 以下の asd を登録する。
(loop for path in (directory (translate-logical-pathname
"home:letter;lisp;clbuild;source;**;*.asd"))
do (let ((pd (pathname-directory path)))
(unless (member "_darcs" pd :test #'equal)
(pushnew (make-pathname :directory pd)
asdf:*central-registry*
:test #'equal))))


;; require で asdf:oos する
(defun asdf-module-provider-function (module)
(when (asdf:find-system module nil)
(asdf:oos 'asdf:load-op module)
t))
(pushnew 'asdf-module-provider-function
ccl::*module-provider-functions*)

(defmethod asdf:perform :around ((o asdf:load-op) (c asdf:cl-source-file))
(handler-case (call-next-method o c)
(#+sbcl sb-ext:invalid-fasl
#+allegro excl::file-incompatible-fasl-error
#+lispworks conditions:fasl-error
#+cmu ext:invalid-fasl
#-(or sbcl allegro lispworks cmu) error ()
(asdf:perform (make-instance 'asdf:compile-op) c)
(call-next-method))))

Clozure CL 本体の他に、clbuid が使いたいので cygwin とか darcs とか git とか svn とかも必要。

./clbuild install hunchentoot

して、

CL-USER> (require :hunchentoot)
CL-USER> (hunchentoot:start (make-instance 'hunchentoot:acceptor :port 1234))

http://localhost:1234/ にアクセス♪

もちろん Meadow と

./clbuild install slime

も必要。ついでに ~/.emacs の SLIME まわりの設定。

(require 'path-util) ; add-path用

(add-path "~/letter/lisp/clbuild/source/slime")
(add-path "~/letter/lisp/clbuild/source/slime/contrib")
(setq slime-lisp-implementations
`((ccl ("/Users/ancient/local/opt/ccl/wx86cl.exe")
:coding-system utf-8-unix)
(sbcl ("sbcl")
:coding-system utf-8-unix)
(clisp ("clisp") :coding-system utf-8-unix)))
(require 'slime-autoloads)
(add-hook 'lisp-mode-hook
(lambda ()
(cond ((not (featurep 'slime))
(require 'slime)
(normal-mode)))))
(setq slime-truncate-lines nil)
(setq slime-enable-evaluate-in-emacs t)
(add-hook
'slime-mode-hook
(lambda ()
(global-set-key [(control ?\;)] 'slime-selector)
(loop for (key command) in
'(("\C-m" newline-and-indent)
("\C-i" slime-indent-and-complete-symbol))
do (define-key slime-mode-map key command))))
(add-to-list 'auto-mode-alist '("\\.asd$" . common-lisp-mode))
(eval-after-load "slime"
'(progn
(slime-setup '(slime-repl slime-asdf slime-fancy slime-banner))
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)))

2009/06/25

cl-openid

ふと OpenID を使ってみようと思った。 Common Lisp にもちゃんと OpenID のライブラリがあった。 CL-OpenID

サンプルがついているのだけど、最近の Hunchentoot では次のように修正する必要があった。 get-parameters と request-uri に hunchetoot::*request* を渡してあげる。

in directory ./examples:
Modified relying-party.lisp
41
- (alist-to-lol (get-parameters))
+ (alist-to-lol (get-parameters hunchentoot:*request*))
52
- (alist-to-lol (get-parameters))
+ (alist-to-lol (get-parameters hunchentoot:*request*))
65
- (alist-to-lol (get-parameters))
+ (alist-to-lol (get-parameters hunchentoot:*request*))
85
- *relying-party* (get-parameters) ; The incoming message alist consists of GET parameters.
- (merge-uris (request-uri) (root-uri *relying-party*))))) ; Figuring out actual request URI may be more complicated with proxies
+ *relying-party* (get-parameters hunchentoot:*request*) ; The incoming message alist consists of GET parameters.
+ (merge-uris (request-uri hunchentoot:*request*) (root-uri *relying-party*))))) ; Figuring out actual request URI may be more complicated with proxies

あとは、こんな感じで動かして http://xxx.xxxx.xx:1234/cl-openid/ にアクセスする。

(require :cl-openid)
(require :cl-openid.examples)

(cl-openid.example-rp::init-relying-party
"http://xxx.xxxx.xx:1234/" "/cl-openid/")

(setq hunchentoot:*show-lisp-errors-p* t)
(hunchentoot:start (make-instance 'hunchentoot:acceptor :port 1234))

examples/relying-party.lisp を見る。 relying-party のインスタンスを作っておく。 handle-openid-request では cond で場合わけ。ふむ、使うぶんには簡単そうだ。

2009/06/22

SBCL にも並列処理の流れ

SBCL の 1.0.29.31 に "Lock-free thread safe queue" が追加された。とてもライブラリ的なものなに処理系に含まれるなんて、並列処理の流れなんだろうな。メッセージパッシングのためのメールボックスの下地なんだろう。いまどきの欲しい機能ではある。

いまのところ queue なので要素の取り出しは dequeue しかない。残念ながら Erlang のパターンマッチングによる選択的な受信は実現できなさそう。

(require :sb-queue)

(defvar *queue* (sb-queue:make-queue))

(sb-queue:enqueue 'foo *queue*)
(sb-queue:enqueue 'bar *queue*)

(sb-queue:dequeue *queue*) ; => FOO, T
(sb-queue:dequeue *queue*) ; => BAR, T

スーツとトンボ

十数年前に買ったスーツがかなりくたびれてきたので、新しくスーツを買った。スーツは客先に行くときだけ。だいたい年の半分は客先。なねど十数年といっても実質は6年ほど。さらに夏用なのでその半分かな。

最近のスーツは細身だね。ノータックだし。涼しげな工夫がいろいろこらされているところはよい。

しかし、スーツは仕事用の作業服なんだよな。そのために何万も出費してしまうのは納得いかないw

子供が小学校から連れてかえったヤゴの最後の一匹が無事にトンボになって飛んでいったらしい。よかった。

2009/06/19

今日のこと

どうして課なんていう古臭くスタティックなものにこだわるのかが分からない。いや、あるめんでは今日気がついた。それを理解することはできないけど。スタティックな組織単位じゃ現状に対応しきれない。 5人いたら、(1 1 1 1 1) (2 1 1 1) (2 2 1) (3 1 1) (3 2) (4 1) (5) のパターン。 10人なら、20人なら。いまの規模では20人の視点がまだ必要だと思う。都度プロジェクト毎に柔軟に組織課すればいい。課長とかの役職は固定であってもいいが、そのメンバーを固定にする必要はないと思う。あぁ、いや、固定にしてほしい人たちがいたから今の状況になってるんだよね。また言うがその気持ちはわからないけど。マイノリティ。スタティックが好きな人もいるんだよね。そして私はダイナミックが好きだ。 Common Lisp が好き。

と書いてはみたが、分からなと好き以外については根拠がない。分析も裏付けも深い考察もシミュレーションも現状把握もない。