131 lines
9.3 KiB
HTML
131 lines
9.3 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Issue AREF-1D Writeup</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="../Issues/iss008_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss009.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss010_w.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss008_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss009.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss010_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue AREF-1D Writeup</H2>
|
|
|
|
<PRE><B>Issue:</B> <A HREF="iss009.htm">AREF-1D</A><P>
|
|
<B>References:</B> Arrays (pp286-298)<P>
|
|
<B>Category:</B> ENHANCEMENT<P>
|
|
<B>Edit history:</B> 22-Apr-87, Version 1 by Pitman<P>
|
|
02-Jun-87, Version 2 by Pitman (<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A>)<P>
|
|
6-Jun-87, Versions 3, 4 by Masinter (editorial)<P>
|
|
11-Jun-87, Version 5, to X3J13 (no changes)<P>
|
|
6-Jul-87, Version 6, by Masinter<P>
|
|
14-Nov-87, Version 7, by Masinter (update discussion)<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
It's hard to write functions like Maclisp's LISTARRAY and FILLARRAY efficiently<P>
|
|
in Common Lisp because they take arguments of varying rank. Currently, you have<P>
|
|
to make a displaced array to work with temporarily and then throw away the<P>
|
|
displaced array when you're done. In many cases, this is bothersome because<P>
|
|
there is no a priori reason why they should have to cons at all.<P>
|
|
<P>
|
|
<B>Proposal (AREF-1D:ROW-MAJOR-AREF):<P>
|
|
</B><P>
|
|
Introduce a new function <A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A> that allows one-dimensional access to<P>
|
|
the storage backing up a given array assuming the normal row-major storage<P>
|
|
layout.<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A> is valid for use with <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>.<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>row-major-aref</B></A> array index [Function]<P>
|
|
<P>
|
|
This accesses and returns the element of array specified by index when the<P>
|
|
elements of array are considered in row-major order. Array may be an array of<P>
|
|
any dimensionality. <A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>row-major-aref</B></A> may be used with <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A>. For reference, the<P>
|
|
following sets of expressions are equivalent:<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>row-major-aref</B></A> array index) ==<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>aref</B></A> (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> (<A REL=DEFINITION HREF="../Body/f_ar_tot.htm#array-total-size"><B>array-total-size</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>array</B></A>)<P>
|
|
:displaced-to <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>array</B></A><P>
|
|
:element-type (<A REL=DEFINITION HREF="../Body/f_ar_ele.htm#array-element-type"><B>array-element-type</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>array</B></A>))<P>
|
|
index)<P>
|
|
<P>
|
|
and<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>aref</B></A> array .. subscripts ..) ==<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>row-major-aref</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>array</B></A> (<A REL=DEFINITION HREF="../Body/f_ar_row.htm#array-row-major-index"><B>array-row-major-index</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>array</B></A> .. subscripts ..))<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
Common Lisp requires row-major storage layout of arrays and has a number of<P>
|
|
operators that allow users to exploit that order. <A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A> is a useful,<P>
|
|
simple addition.<P>
|
|
<P>
|
|
LISTARRAY and FILLARRAY, for example, could be trivially defined by loops that<P>
|
|
had the following form:<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> (I (<A REL=DEFINITION HREF="../Body/f_ar_tot.htm#array-total-size"><B>ARRAY-TOTAL-SIZE</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A>))<P>
|
|
... (<A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> I) ...)<P>
|
|
<P>
|
|
Currently, the only really efficient way to write this would involve something<P>
|
|
like:<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_case_.htm#ecase"><B>ECASE</B></A> (<A REL=DEFINITION HREF="../Body/f_ar_ran.htm#array-rank"><B>ARRAY-RANK</B></A> ARRAY1)<P>
|
|
((0) (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY1) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY2)))<P>
|
|
((1) (<A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> (I (<A REL=DEFINITION HREF="../Body/f_ar_dim.htm#array-dimension"><B>ARRAY-DIMENSION</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> 0))<P>
|
|
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY1 I) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY2 I))))<P>
|
|
((2) (<A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> (I (<A REL=DEFINITION HREF="../Body/f_ar_dim.htm#array-dimension"><B>ARRAY-DIMENSION</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> 0))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> (I (<A REL=DEFINITION HREF="../Body/f_ar_dim.htm#array-dimension"><B>ARRAY-DIMENSION</B></A> <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> 1))<P>
|
|
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY1 I J) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> ARRAY2 I J)))))<P>
|
|
...<A REL=DEFINITION HREF="../Body/f_everyc.htm#some"><B>some</B></A> finite <A REL=DEFINITION HREF="../Body/t_number.htm#number"><B>number</B></A> of clauses...)<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
Many implementations have this primitive under some other name for use<P>
|
|
internally. In Symbolics systems, for example, it is SYS:%1D-AREF.<P>
|
|
<P>
|
|
<B>Adoption Cost:<P>
|
|
</B><P>
|
|
This change is fairly localized. In implementations that already use this<P>
|
|
primitive internally, it's little more than a matter of changing the name of or<P>
|
|
otherwise releasing the existing primitive. In some implementations, it might<P>
|
|
involve writing a small amount of code or compiler work to make <A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A><P>
|
|
work efficiently.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
This gives users efficient access to something to which they already have<P>
|
|
inefficient access.<P>
|
|
<P>
|
|
<B>Conversion Cost:<P>
|
|
</B><P>
|
|
This is an upward-compatible change; the name <A REL=DEFINITION HREF="../Body/f_row_ma.htm#row-major-aref"><B>ROW-MAJOR-AREF</B></A> is unlikely to be<P>
|
|
used by any current program.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
This allows certain programs to be written in a more aesthetic way.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
This issue was conditionally passed at X3J13/June 1987, pending clarification of<P>
|
|
some details. Those clarifications have been made in this version.<P>
|
|
<P>
|
|
</PRE>
|
|
<HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|