1
0
Fork 0
cl-sites/novaspec.org/cl/f_make-array.html

1015 lines
23 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>make-array | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_make-array.html"
><LINK REL="next" HREF="f_adjust-array.html" TYPE="text/html" TITLE="adjust-array"
><LINK REL="prev" HREF="t_simple-bit-vector.html" TYPE="text/html" TITLE="simple-bit-vector"
><LINK REL="up" HREF="15_2_Arrays_Dictionary.html" TYPE="text/html" TITLE="15.2 Arrays Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="15_Arrays.html"
>15. Arrays</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="15_2_Arrays_Dictionary.html"
>15.2 Arrays Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_make-array.html"
>make-array</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="t_simple-bit-vector.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_adjust-array.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="make-array"
></SPAN
><B
>make-array</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><TABLE CELLPADDING="0" CELLSPACING="0"
><TR
><TD VALIGN="BASELINE" ALIGN="LEFT" NOWRAP="NOWRAP"
><B
>make-array</B
><SPAN CLASS="cmssi"
>&#160;</SPAN
><SPAN CLASS="cmssi"
>dimensions</SPAN
><SPAN CLASS="cmtt"
>&#160;</SPAN
><SPAN CLASS="cmtt"
>&amp;key</SPAN
><SPAN CLASS="cmssi"
>&#160;</SPAN
></TD
><TD VALIGN="BASELINE" ALIGN="LEFT"
><SPAN CLASS="cmssi"
>element-type</SPAN
><BR
><SPAN CLASS="cmssi"
>initial-element</SPAN
><BR
><SPAN CLASS="cmssi"
>initial-contents</SPAN
><BR
><SPAN CLASS="cmssi"
>adjustable</SPAN
><BR
><SPAN CLASS="cmssi"
>fill-pointer</SPAN
><BR
><SPAN CLASS="cmssi"
>displaced-to</SPAN
><BR
><SPAN CLASS="cmssi"
>displaced-index-o&#64256;set</SPAN
></TD
></TR
></TABLE
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmssi"
>new-array</SPAN
></DIV
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>dimensions</VAR
> &#8212; a <A HREF="26_1_Glossary.html#designator"
><EM CLASS="term"
>designator</EM
></A
> for a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
> of <A HREF="26_1_Glossary.html#valid_array_dimension"
><EM CLASS="term"
>valid array dimensions</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>element-type</VAR
> &#8212; a <A HREF="26_1_Glossary.html#type_specifier"
><EM CLASS="term"
>type specifier</EM
></A
>. The default is <A HREF="t_t.html" CLASS="typeref"
><B
>t</B
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>initial-element</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>initial-contents</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>adjustable</VAR
> &#8212; a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>. The default is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
><VAR CLASS="param"
>fill-pointer</VAR
> &#8212; a <A HREF="26_1_Glossary.html#valid_fill_pointer"
><EM CLASS="term"
>valid fill pointer</EM
></A
> for the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> to be created, or <SPAN CLASS="misc"
><B
>t</B
></SPAN
> or <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. The default is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
><VAR CLASS="param"
>displaced-to</VAR
> &#8212; an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> or <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. The default is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. This option must not be supplied if either <VAR CLASS="param"
>initial-element</VAR
> or <VAR CLASS="param"
>initial-contents</VAR
> is supplied. </P
><P CLASS="j"
><VAR CLASS="param"
>displaced-index-o&#64256;set</VAR
> &#8212; a <A HREF="26_1_Glossary.html#valid_array_row-major_index"
><EM CLASS="term"
>valid array row-major index</EM
></A
> for <VAR CLASS="param"
>displaced-to</VAR
>. The default is <CODE CLASS="f"
>0</CODE
>. This option must not be supplied unless a <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
> <VAR CLASS="param"
>displaced-to</VAR
> is supplied. </P
><P CLASS="j"
><VAR CLASS="param"
>new-array</VAR
> &#8212; an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>Creates and returns an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> constructed of the most <A HREF="26_1_Glossary.html#specialized"
><EM CLASS="term"
>specialized</EM
></A
> <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> that can accommodate elements of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> given by <VAR CLASS="param"
>element-type</VAR
>. If <VAR CLASS="param"
>dimensions</VAR
> is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
> then a zero-dimensional <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> is created. </P
><P CLASS="j"
><VAR CLASS="param"
>Dimensions</VAR
> represents the dimensionality of the new <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>element-type</VAR
> indicates the <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> of the elements intended to be stored in the <VAR CLASS="param"
>new-array</VAR
>. The <VAR CLASS="param"
>new-array</VAR
> can actually store any <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> of the <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> which results from <A HREF="26_1_Glossary.html#upgrade"
><EM CLASS="term"
>upgrading</EM
></A
> <VAR CLASS="param"
>element-type</VAR
>; see <A HREF="15_1_Array_Concepts.html#sec_15_1_2_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>15.1.2.1</SPAN
> <SPAN CLASS="cmr"
>(Array</SPAN
> <SPAN CLASS="cmr"
>Upgrading)</SPAN
></A
>. </P
><P CLASS="j"
>If <VAR CLASS="param"
>initial-element</VAR
> is supplied, it is used to initialize each <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
> of <VAR CLASS="param"
>new-array</VAR
>. If <VAR CLASS="param"
>initial-element</VAR
> is supplied, it must be of the <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> given by <VAR CLASS="param"
>element-type</VAR
>. <VAR CLASS="param"
>initial-element</VAR
> cannot be supplied if either the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:initial-contents</SPAN
></SPAN
> option is supplied or <VAR CLASS="param"
>displaced-to</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>. If <VAR CLASS="param"
>initial-element</VAR
> is not supplied, the consequences of later reading an uninitialized <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
> of <VAR CLASS="param"
>new-array</VAR
> are undefined unless either <VAR CLASS="param"
>initial-contents</VAR
> is supplied or <VAR CLASS="param"
>displaced-to</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>initial-contents</VAR
> is used to initialize the contents of <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>. For example:</P
><PRE CLASS="screen"
>(make-array '(4 2 3) :initial-contents
'(((a b c) (1 2 3))
((d e f) (3 1 2))
((g h i) (2 3 1))
((j k l) (0 0 0))))</PRE
><P CLASS="j"
><VAR CLASS="param"
>initial-contents</VAR
> is composed of a nested structure of <A HREF="26_1_Glossary.html#sequence"
><EM CLASS="term"
>sequences</EM
></A
>. The numbers of levels in the structure must equal the rank of <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>. Each leaf of the nested structure must be of the <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> given by <VAR CLASS="param"
>element-type</VAR
>. If <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> is zero-dimensional, then <VAR CLASS="param"
>initial-contents</VAR
> specifies the single <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
>. Otherwise, <VAR CLASS="param"
>initial-contents</VAR
> must be a <A HREF="26_1_Glossary.html#sequence"
><EM CLASS="term"
>sequence</EM
></A
> whose length is equal to the first dimension; each element must be a nested structure for an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> whose dimensions are the remaining dimensions, and so on. <VAR CLASS="param"
>Initial-contents</VAR
> cannot be supplied if either <VAR CLASS="param"
>initial-element</VAR
> is supplied or <VAR CLASS="param"
>displaced-to</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>. If <VAR CLASS="param"
>initial-contents</VAR
> is not supplied, the consequences of later reading an uninitialized <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
> of <VAR CLASS="param"
>new-array</VAR
> are undefined unless either <VAR CLASS="param"
>initial-element</VAR
> is supplied or <VAR CLASS="param"
>displaced-to</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>. </P
><P CLASS="j"
>If <VAR CLASS="param"
>adjustable</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>, the array is <A HREF="26_1_Glossary.html#expressly_adjustable"
><EM CLASS="term"
>expressly adjustable</EM
></A
> (and so <A HREF="26_1_Glossary.html#actually_adjustable"
><EM CLASS="term"
>actually adjustable</EM
></A
>); otherwise, the array is not <A HREF="26_1_Glossary.html#expressly_adjustable"
><EM CLASS="term"
>expressly adjustable</EM
></A
> (and it is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
> whether the array is <A HREF="26_1_Glossary.html#actually_adjustable"
><EM CLASS="term"
>actually adjustable</EM
></A
>). </P
><P CLASS="j"
>If <VAR CLASS="param"
>fill-pointer</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>, the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> must be one-dimensional; that is, the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> must be a <A HREF="26_1_Glossary.html#vector"
><EM CLASS="term"
>vector</EM
></A
>. If <VAR CLASS="param"
>fill-pointer</VAR
> is <SPAN CLASS="misc"
><B
>t</B
></SPAN
>, the length of the <A HREF="26_1_Glossary.html#vector"
><EM CLASS="term"
>vector</EM
></A
> is used to initialize the <A HREF="26_1_Glossary.html#fill_pointer"
><EM CLASS="term"
>fill pointer</EM
></A
>. If <VAR CLASS="param"
>fill-pointer</VAR
> is an <A HREF="26_1_Glossary.html#integer"
><EM CLASS="term"
>integer</EM
></A
>, it becomes the initial <A HREF="26_1_Glossary.html#fill_pointer"
><EM CLASS="term"
>fill pointer</EM
></A
> for the <A HREF="26_1_Glossary.html#vector"
><EM CLASS="term"
>vector</EM
></A
>. </P
><P CLASS="j"
>If <VAR CLASS="param"
>displaced-to</VAR
> is <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
>, <A HREF="f_make-array.html" CLASS="funref"
><B
>make-array</B
></A
> will create a <A HREF="26_1_Glossary.html#displaced_array"
><EM CLASS="term"
>displaced array</EM
></A
> and <VAR CLASS="param"
>displaced-to</VAR
> is the <A HREF="26_1_Glossary.html#target"
><EM CLASS="term"
>target</EM
></A
> of that <A HREF="26_1_Glossary.html#displaced_array"
><EM CLASS="term"
>displaced array</EM
></A
>. In that case, the consequences are undefined if the <A HREF="26_1_Glossary.html#actual_array_element_type"
><EM CLASS="term"
>actual array element type</EM
></A
> of <VAR CLASS="param"
>displaced-to</VAR
> is not <A HREF="26_1_Glossary.html#type_equivalent"
><EM CLASS="term"
>type equivalent</EM
></A
> to the <A HREF="26_1_Glossary.html#actual_array_element_type"
><EM CLASS="term"
>actual array element type</EM
></A
> of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> being created. If <VAR CLASS="param"
>displaced-to</VAR
> is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>, the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> is not a <A HREF="26_1_Glossary.html#displaced_array"
><EM CLASS="term"
>displaced array</EM
></A
>. </P
><P CLASS="j"
>The <VAR CLASS="param"
>displaced-index-o&#64256;set</VAR
> is made to be the index offset of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>. When an array A is given as the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:displaced-to</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> to <A HREF="f_make-array.html" CLASS="funref"
><B
>make-array</B
></A
> when creating array B, then array B is said to be displaced to array A. The total number of elements in an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>, called the total size of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>, is calculated as the product of all the dimensions. It is required that the total size of A be no smaller than the sum of the total size of B plus the offset <CODE CLASS="f"
>n</CODE
> supplied by the <VAR CLASS="param"
>displaced-index-o&#64256;set</VAR
>. The effect of displacing is that array B does not have any elements of its own, but instead maps <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>accesses</EM
></A
> to itself into <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>accesses</EM
></A
> to array A. The mapping treats both <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>arrays</EM
></A
> as if they were one-dimensional by taking the elements in row-major order, and then maps an <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>access</EM
></A
> to element <CODE CLASS="f"
>k</CODE
> of array B to an <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>access</EM
></A
> to element <CODE CLASS="f"
>k</CODE
>+<CODE CLASS="f"
>n</CODE
> of array A. </P
><P CLASS="j"
>If <A HREF="f_make-array.html" CLASS="funref"
><B
>make-array</B
></A
> is called with <VAR CLASS="param"
>adjustable</VAR
>, <VAR CLASS="param"
>fill-pointer</VAR
>, and <VAR CLASS="param"
>displaced-to</VAR
> each <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>, then the result is a <A HREF="26_1_Glossary.html#simple_array"
><EM CLASS="term"
>simple array</EM
></A
>. If <A HREF="f_make-array.html" CLASS="funref"
><B
>make-array</B
></A
> is called with one or more of <VAR CLASS="param"
>adjustable</VAR
>, <VAR CLASS="param"
>fill-pointer</VAR
>, or <VAR CLASS="param"
>displaced-to</VAR
> being <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, whether the resulting <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> is a <A HREF="26_1_Glossary.html#simple_array"
><EM CLASS="term"
>simple array</EM
></A
> is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>. </P
><P CLASS="j"
>When an array A is given as the <SPAN CLASS="kwd"
><SPAN CLASS="cmtt"
>:displaced-to</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> to <A HREF="f_make-array.html" CLASS="funref"
><B
>make-array</B
></A
> when creating array B, then array B is said to be displaced to array A. The total number of elements in an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>, called the total size of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>, is calculated as the product of all the dimensions. The consequences are unspecified if the total size of A is smaller than the sum of the total size of B plus the offset <CODE CLASS="f"
>n</CODE
> supplied by the <VAR CLASS="param"
>displaced-index-o&#64256;set</VAR
>. The effect of displacing is that array B does not have any elements of its own, but instead maps <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>accesses</EM
></A
> to itself into <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>accesses</EM
></A
> to array A. The mapping treats both <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>arrays</EM
></A
> as if they were one-dimensional by taking the elements in row-major order, and then maps an <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>access</EM
></A
> to element <CODE CLASS="f"
>k</CODE
> of array B to an <A HREF="26_1_Glossary.html#access"
><EM CLASS="term"
>access</EM
></A
> to <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
> <CODE CLASS="f"
>k</CODE
>+<CODE CLASS="f"
>n</CODE
> of array A.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(make-array 5) ;; Creates a one-dimensional array of five elements.
(make-array '(3 4) :element-type '(mod 16)) ;; Creates a
;;two-dimensional array, 3 by 4, with four-bit elements.
(make-array 5 :element-type 'single-float) ;; Creates an array of single-floats.</PRE
><PRE CLASS="screen"
> (make-array nil :initial-element nil) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #0ANIL
(make-array 4 :initial-element nil) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #(NIL NIL NIL NIL)
(make-array '(2 4)
:element-type '(unsigned-byte 2)
:initial-contents '((0 1 2 3) (3 2 1 0)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #2A((0 1 2 3) (3 2 1 0))
(make-array 6
:element-type 'character
:initial-element #\a
:fill-pointer 3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> "aaa"</PRE
><P CLASS="j"
>The following is an example of making a <A HREF="26_1_Glossary.html#displaced_array"
><EM CLASS="term"
>displaced array</EM
></A
>.</P
><PRE CLASS="screen"
> (setq a (make-array '(4 3)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 4x3 simple 32546632&gt;
(dotimes (i 4)
(dotimes (j 3)
(setf (aref a i j) (list i 'x j '= (* i j)))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(setq b (make-array 8 :displaced-to a
:displaced-index-offset 2))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 8 indirect 32550757&gt;
(dotimes (i 8)
(print (list i (aref b i))))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (0 (0 X 2 = 0))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (1 (1 X 0 = 0))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (2 (1 X 1 = 1))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (3 (1 X 2 = 2))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (4 (2 X 0 = 0))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (5 (2 X 1 = 2))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (6 (2 X 2 = 4))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (7 (3 X 0 = 0))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL</PRE
><P CLASS="j"
>The last example depends on the fact that <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>arrays</EM
></A
> are, in effect, stored in row-major order.</P
><PRE CLASS="screen"
> (setq a1 (make-array 50))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 50 simple 32562043&gt;
(setq b1 (make-array 20 :displaced-to a1 :displaced-index-offset 10))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 20 indirect 32563346&gt;
(length b1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 20
(setq a2 (make-array 50 :fill-pointer 10))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 50 fill-pointer 10 46100216&gt;
(setq b2 (make-array 20 :displaced-to a2 :displaced-index-offset 10))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 20 indirect 46104010&gt;
(length a2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 10
(length b2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 20
(setq a3 (make-array 50 :fill-pointer 10))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 50 fill-pointer 10 46105663&gt;
(setq b3 (make-array 20 :displaced-to a3 :displaced-index-offset 10
:fill-pointer 5))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;ARRAY 20 indirect, fill-pointer 5 46107432&gt;
(length a3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 10
(length b3) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 5</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_adjustable-array-p.html" CLASS="funref"
><B
>adjustable-array-p</B
></A
>, <A HREF="f_aref.html" CLASS="funref"
><B
>aref</B
></A
>, <A HREF="f_arrayp.html" CLASS="funref"
><B
>arrayp</B
></A
>, <A HREF="f_array-element-type.html" CLASS="funref"
><B
>array-element-type</B
></A
>, <A HREF="v_array-rank-limit.html" CLASS="conref"
><B
>array-rank-limit</B
></A
>, <A HREF="v_array-dimension-limit.html" CLASS="conref"
><B
>array-dimension-limit</B
></A
>, <A HREF="f_fill-pointer.html" CLASS="funref"
><B
>fill-pointer</B
></A
>, <A HREF="f_upgraded-array-element-type.html" CLASS="funref"
><B
>upgraded-array-element-type</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>There is no specified way to create an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> for which <A HREF="f_adjustable-array-p.html" CLASS="funref"
><B
>adjustable-array-p</B
></A
> definitely returns <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>. There is no specified way to create an <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> that is not a <A HREF="26_1_Glossary.html#simple_array"
><EM CLASS="term"
>simple array</EM
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="t_simple-bit-vector.html" CLASS="prev"
>&#8592;</A
><A HREF="f_adjust-array.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>