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-07-27

.14

| 00:37 | .14 - わだばLisperになる を含むブックマーク はてなブックマーク - .14 - わだばLisperになる

日課練習、SRFI-1 unfold

(defun unfold (p f g seed &optional (tail-gen #'(lambda (x) (declare (ignore x)) '())))
  (if (funcall p seed)
      (funcall tail-gen seed)
      (cons (funcall f seed)
	    (unfold p f g (funcall g seed) tail-gen))))

(defun unfold (p f g seed &optional (tail-gen #'(lambda (x) (declare (ignore x)) '())))
  (do ((seed seed (funcall g seed))
       (result '() (cons (funcall f seed) result)))
      ((funcall p seed) (nreconc result (funcall tail-gen seed)))))

(defun unfold (p f g seed &optional (tail-gen #'(lambda (x) (declare (ignore x)) '())))
  (do* ((s seed (funcall g s))
	(result (list s))
	(splice result (cdr (rplacd splice (list (funcall f s))))))
       ((funcall p s) (append result (funcall tail-gen s)))))