all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* manual
@ 2008-04-08  9:27 David Roderick
  2008-04-08 21:10 ` manual Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: David Roderick @ 2008-04-08  9:27 UTC (permalink / raw)
  To: bug-gnu-emacs


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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: manual
  2008-04-08  9:27 manual David Roderick
@ 2008-04-08 21:10 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2008-04-08 21:10 UTC (permalink / raw)
  To: David Roderick; +Cc: bug-gnu-emacs

> 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.

I'm not sure I understand the question.  It seems you are asking of both
`function' and `sequence' are evaluated, but that's clearly the case,
since `mapcar' is a function and Elisp is not a lazy language: all
arguments to a function are evaluated before passing them to
the function.


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-04-08 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-08  9:27 manual David Roderick
2008-04-08 21:10 ` manual Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.