I saw this example code:
(mapcar '1+ '(2 4 6))
⇒ (3 5 7)
But I do not understand '1+
here. it will apply a function to a list but this style obviously not like a function. If means add, the function should be +, what does '1+
mean?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityIt's really a function, which means add 1. you can try below example:
ELISP> (1+ 3)
4 (#o4, #x4, ?\C-d)
The implementation is at data.c:
DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
Markers are converted to integers. */)
(register Lisp_Object number)
{
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
if (FLOATP (number))
return (make_float (1.0 + XFLOAT_DATA (number)));
XSETINT (number, XINT (number) + 1);
return number;
}
'1+
is a reference to the function stored in that symbol, in this case it returns number incremented by 1. mapcar
applies it to every element of the list, and then returns the resulting list.
1+
is the name of a function:C-h f 1+ RET
– phils Feb 17 '17 at 23:221-
function which returns its argument minus 1. That one is also slightly less intuitive when looking at the code:(1- 3) => 2
. – phils Feb 18 '17 at 4:02