2010/10/12

Series の collect-ignore

Series は遅延評価だから collect-ignore みたいな何もしない人が必要になるんだねぇ。

(eval-when (:compile-toplevel :load-toplevel :execute)
(require :series))

(defpackage :s
(:use :cl :series))

(in-package :s)

(series::install)

(let (x)
(map-fn t (lambda (n) (push n x)) (scan '(1 2 3)))
x)
;; => NIL

(let (x)
(collect-ignore (map-fn t (lambda (n) (push n x)) (scan '(1 2 3))))
x)
;; => (3 2 1)

ちなみに collect-ignore の定義は次のとおり。さっぱり分かる気がしない。

;; API
(defS collect-ignore (items)
"(collect-ignore series)

Like COLLECT, but any output that would have been returned is
discarded. In particular, no results are consed at all."

(fragl ((items t)) (nil) () () () () () () nil)
:trigger t)

series:iterate の中の方で collect-ignore が使われている。これが series:iterate と series:mapping の違いということなんだね。

(defmacro iterate-mac (var-value-list &rest body)
"Applies BODY to each element of the series"
`(collect-ignore (mapping ,var-value-list ,@ body)))

0 件のコメント: