Emacs-Lisp > mapcar

概要

  • 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))


呼出元

コメント:

履歴

  • 作者:kobapan
  • 日付:2009/01/03
  • 対象:
更新日 更新者 更新内容

コメント

名前:
コメント:
最終更新:2009年06月07日 21:15