Hatena::Groupcadr

わだばLisperになる このページをアンテナに追加 RSSフィード

2004 | 12 |
2005 | 01 | 02 | 07 | 10 | 11 |
2006 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2011 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 11 |

2007-08-06

SRFI-87 case

| 14:35 | SRFI-87 case - わだばLisperになる を含むブックマーク はてなブックマーク - SRFI-87 case - わだばLisperになる

日課練習、SRFI-87 caseの=>拡張

マクロでペタペタ。

(defmacro case87 (&body form)
  (let ((clauses (cdr form)))
    (if (=>-finder clauses)
	(let ((eform)
	      (gs (gensym))
	      (key (car form)))
	  (dolist (clause clauses `(let ((,gs ,key)) (case ,key ,@(nreverse eform))))
	    (if (eq '=> (second clause))
		(destructuring-bind (key => receiver) clause
		  (declare (ignore =>))
		  (push `(,key ((lambda (x) (funcall ,receiver x)) ,gs)) eform))
		(push clause eform))))
	`(case ,@form))))

(defun =>-finder (form)
  (dolist (x form nil)
    (and (find '=> x :test #'eq)
	 (return-from =>-finder t))))