概要
- Function: mapcar FUNCTION SEQUENCE
`mapcar'は、SEQUENCEの各要素に順にFUNCTIONを適用し、結果のリストを返す。
引数SEQUENCEは文字テーブル以外の任意の種類のシーケンスでよい。つま
り、リスト、ベクトル、ブールベクトル、あるいは、文字列である。結果
はつねにリストである。結果の長さはSEQUENCEの長さと同じである。
たとえば、つぎのとおり。
(mapcar 'car '((a b) (c d) (e f)))
=> (a c e)
(mapcar '1+ [1 2 3])
=> (2 3 4)
(mapcar 'char-to-string "abc")
=> ("a" "b" "c")
;; `my-hooks'の各関数を呼び出す
(mapcar 'funcall my-hooks)
(defun mapcar* (function &rest args)
"Apply FUNCTION to successive cars of all ARGS.
Return the list of results."
;; リストをつくしていなければ
(if (not (memq 'nil args))
;; CARに関数を適用する
(cons (apply function (mapcar 'car args))
(apply 'mapcar* function
;; Recurse for rest of elements.
(mapcar 'cdr args)))))
(mapcar* 'cons '(a b c) '(1 2 3 4))
=> ((a . 1) (b . 2) (c . 3))
呼出元
履歴
コメント
最終更新:2009年06月07日 21:15