lisp batton - common lisp
TRANSCRIPT
Common Lisp コードバトン
#1 g000001
R6RS SchemeからCLに翻訳してみた
CLには、標準ではmatchがないそれ程複雑なパターンマッチでもない様子辞書エントリーのアクセサを定義すればOKかもしれない
アクセサが欲しかったので、defstruct(:type list)で構造体を定義
entry-というアクセサ
make-で定義した構造のリストも作れる
(defstruct (entry (:type list)) word meaning ok-count ng-count)
(defun nomalize-dict (dict) (mapcar (lambda (e) (make-entry :word (entry-word e) :meaning (entry-meaning e) :ok-count (or (entry-ok-count e) 0) :ng-count (or (entry-ng-count e) 0))) dict))
.
sortには:keyを指定できるので単純に書ける
(defun sort-word-spec* (word-spec*) (sort word-spec* #'> :key (lambda (e) (- (entry-ng-count e) (entry-ok-count e)))))
再帰をやめてループ
(defun main (file) (let ((dict (sort-word-spec* (read-dict file)))) (dolist (e dict) (pr "~&~A: " (entry-word e)) (ready?) (pr "~&~A y/n? " (entry-meaning e)) :again (case (query) ((#\Y #\y) (incf (entry-ok-count e))) ((#\N #\n) (incf (entry-ng-count e))) ((#\Q #\q) (return)) (otherwise (pr "~&Please type Y for yes or N for no or Q for quit.~%") (go :again)))) (write-dict file dict)))
#2 aka英単語を登録できる関数追加 (hige:pin)辞書のCSV一覧表示関数追加 (hige:pun)名前空間周りの整理
case-sensitivepackage名での管理
read-char,clear-inputのシーケンスread-lineに変更
documentationストリングをまめに書く処理に無駄がないように、read time evaluation活用制御に関わる部分は命令的に。関数の性質がある部分は関数的に。
aka
正答率でソートする部分は、学習効率を高めるためのストラテジの部分なので、関数として外に出して交換しやすく(sort-dict-standard)とにかくCLらしく、ということで、(lambda を#'(lambdaにかえたり
#3 quek
"~" という処理系拡張を解釈しない処理系のために
(merge-pathnames ".hige/words.txt" (user-homedir-pathname)(probe-file dict-file) で辞書ファイルの存在をチェック
辞書ファイルがない場合は
(ensure-directories-exist dict-file) でディレクトリだけは作成しておく
#4 snmsts
ABCLとswingでぬるめのUI(ABCL限定)
#5 (び)
SBCL+Mac OS X縛りで出題単語を読
み上げ
(sayコマンドを利用)
#6 naoya_t
辞書から単語をassocしてくる search-dict を実装単語を入力し、search-dict で検索し、見つかれば意味を、見つからなければ "Not found." と返す(hige:pan)を実装
aifマクロを追加
(loop :for ... :in ... :do ...) を dolist で置き換えてみた
#7 masatoi
iKnow!風にn択問題(hige:pen)を実装.英単語から意味を問うのと意味から英単語を問うのと選べる繰り返しはnamed-let
;; named-let macro (from "Let Over Lambda")
(defmacro nlet (tag var-vals &body body) `(labels ((,tag ,(mapcar #'car var-vals) ,@body)) (declare (optimize (speed 3))) ; for tail recursion optimization
(,tag ,@(mapcar #'cadr var-vals))))
#8 cranebird
with-系のマクロを追加
CLと言えばマルチパラダイムなので CLOSで
(defclass dict () ((entries :accessor entries-of :initform nil :initarg :entries :documentation "Entries")) (:documentation "Container class"))
cranebird
print-objectを定義
CL-USER> (hige::make-dict '((hige "ひげ" 0 0)))
#<dict: entries: 1 total/ok/ng: 0/0/0>
#9 smeghead
問題の単語表示時にもスコアを表示するように
単語の一覧表示(hige:pun)で指定したスコア以下の単語のみを表示する機能を追加。問題の単語表示時にもスコアを表示するように
[5]> (hige:pun :score-threshold 5)starbug1,スターバグ1号,3,0
river,川,5,0
NIL[6]>
#10 NANRI
untabifyformat指示子を大文字に揃える
"~a~%" => "~A~%"インデントを調整辞書が存在しない時の動作を修正パッケージ名がprintされないようにしてみやすくasdfのパッケージ化
(asdf-install:install "http://gist.github.com/gists/280060/download")でインストールできるようになった
#11 snmsts 2回目
(び)さんの変更がSBCL+OS Xなので
read-time conditionalizationをらしく修正
#+(and SBCL DARWIN) (sb-ext:run-program "/usr/bin/say" `(,(symbol-name word)) :wait t)
#12 making辞書ファイルをhttp経由で取得できるようにした。要drakma(ウェブクライアント)。
(hige:pin "http://gist.github.com/273424.txt")
でウェブから辞書を取得できる
#13 深町英太郎単語登録時に意味を空にした際にGoogle翻訳の結果を登録できるように。要cl-ppcre。
(defun prompt-for-translate (word) ...)))
(defun google-translate (word) ...))))
#14 kurohuku
Gray Stream(オブジェクト指向なストリーム)を利用して暗記ゲームの回答時にログをファイル出力
CL-USER> (hige:Pon);; setup dict...donelisp (score: 0):
舌足らず [Ynq]: Y ;Yと解答した時点でログが出力されて欲しい
#15 kosh
空のエントリを登録しないようにした(add empty-entry-p)
(defun empty-entry-p (entry) ...)) (defun add-entry (entry &key (if-exists :overwrite)) ...)))
ログファイルもディレクトリがない場合は作成するように(ensure-directories-exist ,filename)
(newLisp版も作成)
そして伝説へ…
まとめ
参加した人は結構楽しんでいた様子
勉強になるよ
またやろうよ
参加してね