nth


(nth  index  lst)

This function returns the index element from list lst.

Arguments

index  integer, the index of the value to be retrieved; first element in a list uses index 0

lst  any list, to retrieve the specified index value from

Return

the lst item at specified index; if index is equal or greater than the number of items in lst, NIL is returned

Example

(nth 1 '(a b c d))  returns b
(nth 3 '(a b c d))  returns d
(nth 4 '(a b c d))  returns NIL

Remarks

if index is negative, an error is triggered;


often used code like
(nth 0 lst)  (nth 1 lst))
should be changed to
(car lst)  (cadr lst)
as this is processed significantly faster



©  Bricsys NV. All rights reserved.