Source of Nothingness - clispでcgi

* clispcgi

とりあえずで作ったsplit-string
(defun split-string (string &optional (separator " "))
  (let ((n (position separator string :test #'(lambda (x y)
                                                (find y x :test #'char=)))))
    (if n
        (cons (subseq string 0 n) (split-string (subseq string (1+ n)) separator))
      (cons string nil))))
あとで末尾再帰へ書き直ししないと。

ファイルの入出力のときに「Bad address」のエラーが出ているみたい。
一応入出力には成功しているんだけど。

日本語関係をちゃんとすれば簡単な一行掲示板になるかな。


末尾再帰バージョン
(defun split-string (string &optional (separator " "))
  (split-string-1 string separator))

(defun split-string-1 (string &optional (separator " ") (r nil))
  (let ((n (position separator string :from-end t :test #'(lambda (x y) (find y x :test #'char=)))))
    (if n
        (split-string-1 (subseq string 0 n) separator (cons (subseq string (1+ n)) r))
      (cons string r))))
実行環境がないので未テスト。

update : 2006-03-13 (Mon) 12:31:40