Nth
The nth element (zero-based) of a list
(Nth n l) is the nth element of l, zero-based. If
n is greater than or equal to the length of l, then nth returns
nil.
(Nth n l) has a guard that n is a non-negative integer and
l is a true-listp.
Nth is a Common Lisp function. See any Common Lisp documentation for
more information.
Function: nth
(defun nth (n l)
(declare (xargs :guard (and (integerp n)
(>= n 0)
(true-listp l))))
(if (endp l)
nil
(if (zp n)
(car l)
(nth (- n 1) (cdr l)))))
Subtopics
- Std/lists/nth
- Lemmas about nth available in the std/lists library.
- Nth-aliases-table
- A table used to associate names for nth/update-nth printing
- Equal-by-nths
- Proof technique: show two lists are equal by showing that their
nth elements are always the same.
- First
- First member of the list
- Rest
- Rest (cdr) of the list
- Third
- Third member of the list
- Tenth
- Tenth member of the list
- Sixth
- Sixth member of the list
- Seventh
- Seventh member of the list
- Second
- Second member of the list
- Ninth
- Ninth member of the list
- Fourth
- Fourth member of the list
- Fifth
- Fifth member of the list
- Eighth
- Eighth member of the list