テキストブラウザ #5

2個マクロ書いた。initscr と endwin とエラー処理(何もしてないけど)を纏めるwith-cursesと、キーボード入力待ちループ用のinput-loopです。しかし、それほど呼び出し側のコードがすっきりするわけでも無かった。

(defmacro with-curses (&body body)
`(handler-case
(progn
(initscr)
,@body
(endwin))
(error (c)
(endwin)
(apply #'format t
(simple-condition-format-control c)
(simple-condition-format-arguments c)))))
(defmacro input-loop (key &body test-proc-lst)
`(loop for ,key = (getch)
do (cond
,@(loop for test-proc in test-proc-lst
collect (if (and (listp (car test-proc)) (not (fboundp (car (car test-proc)))))
`((member ,key (list ,@(car test-proc)) :test #'equal) (progn ,@(cdr test-proc)))
`((equal ,key ,(car test-proc)) (progn ,@(cdr test-proc))))))))

gensymの使いどころがわかってないけど、input-loop の引数 key は、gensymが必要なんだろうか?

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


The reCAPTCHA verification period has expired. Please reload the page.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください