I want to write a small function开发者_StackOverflow中文版 to add a value to a list. it looks like this:
(defvar fares '(31.14 28.12 25.10 22.08 19.06 16.04 13.02 10))
(defun plus-extra (fare) (+ 3.02 fare))
(map 'plus-extra fares)
Fairly predictably, the elisp barfs because the function needs an argument. What am I missing?
Thanks Robert
The function which doesn't have enough argument here is map
, not the one you defined.
The map
function does not exists in Emacs Lisp, it is provided by the cl
package. This map
function require 3 arguments, the first one must be the type of what map
should return. This:
(map 'list 'plus-extra fares)
will work. But what you want is this:
(mapcar 'plus-extra fares)
which is native elisp.
PS: Don't forget that Emacs comes with its documentation! C-h f map RET ;-).
Use mapcar
, not map
. With mapcar
, your example yields:
(34.160000000000004 31.14 28.12 25.099999999999998 22.08 19.06 16.04 13.02)
If you M-x describe-function RET map RET
, you'll see the signature of map
is not what you expected:
(map TYPE FUNCTION SEQUENCE...)
Map a FUNCTION across one or more SEQUENCEs, returning a sequence.
TYPE is the sequence type to return.
精彩评论