How can I get the first N elements of a list?
I know I can use subseq
:
(subseq '("one" "two" "three" "four" "five") 0 2)
Yet when I use subseq
, it produces one of the following results:
- on the first call, the message
"function 'subseq' from cl package called at runtime"
or, - an error that
"progn: Symbol’s function definition is void: subseq"
when using vanillaemacs -Q
.
I could overcome these by using (require 'cl-extras)
or cl-subseq
. But given these hiccups, I expect there is a more direct way to get the first N elements.
Looking through documentation didn't turn up anything and the implementation of cl-subseq
is non-trivial. If a builtin doesn't exist, I imagine to implement from scratch would require something like "Get the car
of each cdr
". Yet, this makes me think of loop
... which is also a cl
extension.
Thoughts?