2012/02/22

fset:map も Series 化してみた

Series は sequence と hash-table は別関数なので FSet の場合でも map だけは別あつかいかな。

(series::defS scan-map (map)
"(scan map)

Scans the entries of the fset:map and returns two series containing
the keys and their associated values. The first element of key series
is the key of the first entry in the fset:map, and the first element
of the values series is the value of the first entry, and so on. The
order of scanning the fset:map is not specified."

(series::fragl ((map)) ; args
((keys t) (values t)) ; rets
((keys t) (values t) ; aux
(mapptr t map))
() ; alt
() ; prolog
((if (fset:empty? mapptr) (go series::end)) ; body
(multiple-value-bind (key val) (fset:arb mapptr)
(setq keys key)
(setq values val))
(setq mapptr (fset:less mapptr keys)))
() ; epilog
() ; wraprs
nil))

(series::defS collect-map (keys values &optional default-value)
"(collect-map keys values)

Combines a series of keys and a series of values together into a map of fset.
default-value is defalt of fset:empty-map."

(series::fragl ((keys t) (values t) (default-value t))
((map))
((map 'fset:map (fset:empty-map default-value)))
()
()
((setq map (fset:with map keys values)))
()
()
nil)
:trigger t)

;; キーと値をひっくり返した map を返す。
(multiple-value-bind (k v)
(scan-map (fset:map ('a 1) ('b 2) ('c 3)))
(collect-map v k 'not-found))
;;=> #{| (1 A) (2 B) (3 C) |}/NOT-FOUND

0 件のコメント: