User Tools


Differences

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

Link to this comparison view

cl:functions:aref [2019/09/14 05:00]
cl:functions:aref [2019/09/20 16:00] (current)
Line 1: Line 1:
 +====== Accessor AREF ======
 +
 +====Syntax====
 +  * **aref** //array ''&​rest''​ subscripts//​ → //element//
 +  * (**setf** (**aref** //array ''&​rest''​ subscripts//​) //​new-element//​)
 +
 +====Arguments and Values====
 +  * //array// - an //​[[CL:​Glossary:​array]]//​.
 +  * //​subscripts//​ - a //​[[CL:​Glossary:​list]]//​ of //​[[CL:​Glossary:​valid array index|valid array indices]]// for the //array//.
 +  * //​element//,​ //​new-element//​ - an //​[[CL:​Glossary:​object]]//​.
 +
 +====Description====
 +//​[[CL:​Glossary:​access|Accesses]]//​ the //array// //​[[CL:​Glossary:​element]]//​ specified by the //​subscripts//​. If no //​subscripts//​ are supplied and //array// is zero rank, //aref// //​[[CL:​Glossary:​accesses]]//​ the sole element of //array//.
 +
 +//aref// ignores //​[[CL:​Glossary:​fill pointers]]//​. It is permissible to use //aref// to //​[[CL:​Glossary:​access]]//​ any //array// //​[[CL:​Glossary:​element]]//,​ whether //​[[CL:​Glossary:​active]]//​ or not.
 +
 +====Examples====
 +If the variable ''​foo''​ names a 3-by-5 array, then the first index could be 0, 1, or 2, and then second index could be 0, 1, 2, 3, or 4. The array elements can be referred to by using the function **aref**; for example, ''​(aref foo 2 1)''​ refers to element (2, 1) of the array.
 +
 +<​blockquote>​
 +([[CL:​Macros:​defparameter]] *alpha* ([[CL:​Functions:​make-array]] 4)) <​r>​*ALPHA*</​r>​
 +(aref *alpha* 3) <​r>//​[[CL:​Glossary:​implementation-dependent]]//​ </r>
 +([[CL:​Macros:​setf]] (aref *alpha* 3) '​sirens) <​r>​SIRENS </r>
 +(aref *alpha* 3) <​r>​SIRENS</​r>​
 +
 +([[CL:​Macros:​defparameter]] *beta* ​
 +  ([[CL:​Functions:​make-array]] '(2 4) :​element-type '​(unsigned-byte 2) 
 +                     :​initial-contents '((0 1 2 3) (3 2 1 0)))) <​r>​*BETA*</​r>​
 +(aref *beta* 1 2) <r>1 </r>
 +([[CL:​Macros:​defparameter]] *gamma* '(0 2)) <​r>​*GAMMA*</​r>​
 +([[CL:​Functions:​apply]] #'aref *beta* *gamma*) <r>2 </r>
 +([[CL:​Macros:​setf]] ([[CL:​Functions:​apply]] #'aref *beta* *gamma*) 3) <r>3 </r>
 +([[CL:​Functions:​apply]] #'aref *beta *gamma*) <r>3 </r>
 +(aref *beta* 0 2) <​r>​3</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +**[[CL:​Functions:​bit|Function BIT]]**, **[[CL:​Functions:​char|Function CHAR]]**, **[[CL:​Functions:​elt|Function ELT]]**, **[[CL:​Functions:​row-major-aref|Function ROW-MAJOR-AREF]]**,​ **[[CL:​Functions:​svref|Function SVREF]]**, {\secref\ConstantModification}
 +
 +====Notes====
 +None.
 +
 +\issue{CONSTANT-MODIFICATION:​DISALLOW} \issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:​ALL-FIXNUM}