From: David Roderick <angel_ov_north@tiscali.co.uk>
To: bug-gnu-emacs@gnu.org,
Subject: manual
Date: Tue, 08 Apr 2008 10:27:11 +0100 [thread overview]
Message-ID: <uve2sd7dc.fsf@tiscali.co.uk> (raw)
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
next reply other threads:[~2008-04-08 9:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-08 9:27 David Roderick [this message]
2008-04-08 21:10 ` manual Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=uve2sd7dc.fsf@tiscali.co.uk \
--to=angel_ov_north@tiscali.co.uk \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).