Function: take
take is a function defined in fns.c.
Signature
(take N LIST)
Documentation
Return the first N elements of LIST.
If N is zero or negative, return nil. If N is greater or equal to the length of LIST, return LIST (or a copy).
Other relevant functions are documented in the list group.
Probably introduced at or before Emacs version 29.1.
Shortdoc
;; list
(take 3 '(one two three four))
=> (one two three)
Aliases
Source Code
// Defined in /usr/src/emacs/src/fns.c
{
EMACS_INT m;
if (FIXNUMP (n))
{
m = XFIXNUM (n);
if (m <= 0)
return Qnil;
}
else if (BIGNUMP (n))
{
if (mpz_sgn (*xbignum_val (n)) < 0)
return Qnil;
m = MOST_POSITIVE_FIXNUM;
}
else
wrong_type_argument (Qintegerp, n);
CHECK_LIST (list);
if (NILP (list))
return Qnil;
Lisp_Object ret = Fcons (XCAR (list), Qnil);
Lisp_Object prev = ret;
m--;
list = XCDR (list);
while (m > 0 && CONSP (list))
{
Lisp_Object p = Fcons (XCAR (list), Qnil);
XSETCDR (prev, p);
prev = p;
m--;
list = XCDR (list);
}
if (m > 0 && !NILP (list))
wrong_type_argument (Qlistp, list);
return ret;
}