[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
manual
From: |
David Roderick |
Subject: |
manual |
Date: |
Tue, 08 Apr 2008 10:27:11 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (windows-nt) |
12.6 Mapping Functions
======================
-- Function: mapcar function sequence
`mapcar' applies FUNCTION to each element of SEQUENCE in turn, and
returns a list of the results.
DOES the function as mapcar evaluate both function and sequence, or
merely function and not sequence.
This information is crucial and missing.
Crucial because
is definition til mapcar*
(cons (apply function (mapcar 'car args))
args will be inside of a list because of &rest
If 'car is to be applied by (arg1 arg2 arg3)
it cannot be car
because the evaluation til car would occur twice giving evalutation til
the subr of a symbols function-cell as #<subr car>.
Therefore by mapcar function sequence, evalutation til function does
occur.
What about the sequence?
No idea. My guess is not. eval til (arg1 arg2 arg3) would require arg1
to be a symbol with a its function-cell occupied.
Answers should be put into Elisp manual.
If correct my deduction took 30 mins.
Not necessary if this explanation is put in.
Advise to include this if I am not mistaken.
The argument SEQUENCE can be any kind of sequence except a
char-table; that is, a list, a vector, a bool-vector, or a string.
The result is always a list. The length of the result is the
same as the length of SEQUENCE. For example:
(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")
;; Call each function in `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 no list is exhausted,
(if (not (memq nil args))
;; apply function to CARs.
(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))
--
from
David Roderick
- manual,
David Roderick <=