User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:nth [2019/07/14 17:00]
cl:functions:nth [2019/09/20 06:00] (current)
Line 1: Line 1:
 +====== Accessor NTH ======
  
 +====Syntax====
 +  * **nth** //n list// → //object//
 +  * (**setf** (**nth** //n list//) //​new-object//​)
 +
 +====Arguments and Values====
 +  * //n// - a non-negative //​[[CL:​Glossary:​integer]]//​.
 +  * //list// - a //​[[CL:​Glossary:​list]]//,​ which might be a //​[[CL:​Glossary:​dotted list]]// or a //​[[CL:​Glossary:​circular list]]//.
 +  * //object// - an //​[[CL:​Glossary:​object]]//​.
 +  * //​new-object//​ - an //​[[CL:​Glossary:​object]]//​.
 +
 +====Description====
 +**nth** locates the //n//th element of //list//, where the //​[[CL:​Glossary:​car]]//​ of the //list// is the "​zeroth"​ element. Specifically,​
 +
 +<​blockquote>​
 +(nth //n// //list//) ≡ ([[CL:​Functions:​car]] ([[CL:​Functions:​nthcdr]] //n// //list//))
 +</​blockquote>​
 +
 +**nth** may be used to specify a //place// to **[[CL:​Macros:​setf]]**. Specifically,​
 +
 +<​blockquote>​
 +([[CL:​Macros:​setf]] (nth //n// //list//) //​new-object//​) ≡ ([[CL:​Macros:​setf]] ([[CL:​Functions:​car]] ([[CL:​Functions:​nthcdr]] //n// //list//)) //​new-object//​)
 +</​blockquote>​
 +
 +====Examples====
 +<​blockquote>​
 +(nth 0 '(foo bar baz)) <​r>​FOO</​r>​
 +(nth 1 '(foo bar baz)) <​r>​BAR</​r>​
 +(nth 3 '(foo bar baz)) <​r>​[[CL:​Constant Variable:​nil|NIL]]</​r>​
 +([[CL:​Macros:​defparameter]] *0-to-3* ([[CL:​Functions:​list]] 0 1 2 3)) <​r>​*0-TO-3*</​r>​
 +([[CL:​Macros:​setf]] (nth 2 *0-to-3*) "​two"​) <​r>"​two"</​r>​
 +*0-to-3* <r>(0 1 "​two"​ 3)</​r>​
 +</​blockquote>​
 +
 +====Side Effects====
 +None.
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +**[[CL:​Functions:​elt|Function ELT]]**, **[[CL:​Functions:​first|Function FIRST]]**, **[[CL:​Functions:​nthcdr|Function NTHCDR]]**
 +
 +====Example Implementation====
 +To be done.
 +
 +====Notes====
 +None.
 +
 +\issue{DOTTED-LIST-ARGUMENTS:​CLARIFY}