1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss093_w.htm
2024-04-01 10:24:07 +02:00

149 lines
11 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 DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES 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/iss092_w.htm">
<LINK REL=UP HREF="../Issues/iss093.htm">
<LINK REL=NEXT HREF="../Issues/iss094_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/iss092_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss093.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss094_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES Writeup</H2>
<PRE><B>Status:</B> Passed, Jan 89 X3J13<P>
<P>
<B>Issue:</B> <A HREF="iss093.htm">DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES</A><P>
<P>
<B>References:</B> Array type specifiers, pp. 45-46<P>
<P>
Related issues: <A HREF="iss015.htm">ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS</A>, <A HREF="iss096.htm">DECLARE-TYPE-FREE</A>,<P>
<A HREF="iss337.htm">SYMBOL-MACROLET-DECLARE</A><P>
<P>
<B>Category:</B> CHANGE<P>
<P>
<B>Edit history:</B> Version 1, 7-Oct-88, Pierson<P>
Version 2, 13-Jan-89, Pierson (Moon and JonL comments)<P>
Version 3, 13-Jan-89, Pierson (Pitman comments)<P>
<P>
<B>Problem description:<P>
</B><P>
In principle, array type specifiers could be used both for declaring<P>
the storage format of the array and for implicitly declaring the types<P>
of the elements held by those arrays. Unfortunately, the current <P>
definition of the meaning of array type specifiers does not explicitly<P>
specify that the latter use of these declarations is legitimate.<P>
<P>
<B>Proposal (DECLARE-ARRAY-TYPE-ELEMENT-REFERENCES:RESTRICTIVE):<P>
</B><P>
Within the lexical scope of an array type declaration, all references<P>
to array elements are assumed to satisfy the exact declared element<P>
type. It is an error if this is ever violated. A compiler may treat<P>
the code within the scope of the array type declaration as if each<P>
access of an array element was surrounded by an appropriate <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> form.<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/m_defpar.htm#defvar"><B>DEFVAR</B></A> *ONE-ARRAY* (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> 10 :ELEMENT-TYPE '(<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5)))<P>
(<A REL=DEFINITION HREF="../Body/m_defpar.htm#defvar"><B>DEFVAR</B></A> *ANOTHER-ARRAY* (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> 10 :ELEMENT-TYPE '(<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 8)))<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> FROB (AN-ARRAY)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) 1) AN-ARRAY))<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> AN-ARRAY 1) 31) ; OK<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> AN-ARRAY 2) 127) ; Should <A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>signal</B></A> an <A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>error</B></A><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> AN-ARRAY 3) (* 2 (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 3))) ; Run-time decision needed<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((FOO 0))<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) FOO))<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> FOO (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 0)))) ; Declared to be safe<P>
<P>
(FROB *ONE-ARRAY*) ; Legal call, should <A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>signal</B></A> an <A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>error</B></A><P>
(FROM *ANOTHER-ARRAY*) ; Is probably an undetectable <A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>error</B></A><P>
<P>
Note that the above definition of FROB is equivalent to:<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> FROB (AN-ARRAY)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) 1) AN-ARRAY))<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 1) 31))<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 2) 127))<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 3))<P>
(* 2 (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 3))))<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((FOO 0))<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) FOO))<P>
(<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> FOO (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 5) (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> AN-ARRAY 0)))))<P>
<P>
Given an implementation in which fixnums are 29 bits but <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>fixnum</B></A> arrays<P>
are upgraded to signed 32-bit arrays, the following should be compiled<P>
with all <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>fixnum</B></A> arithmetic:<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> BUMP-COUNTERS (COUNTERS)<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> *) BUMP-COUNTERS))<P>
(<A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> (I (<A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A> COUNTERS))<P>
(<A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>INCF</B></A> (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> COUNTERS I))))<P>
<P>
<B>Test Cases:<P>
</B><P>
TBS<P>
<P>
<B>Rationale:<P>
</B><P>
This mandates a useful and commonly expected behavior. It complements<P>
proposal <A HREF="iss015.htm">ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS</A>, which deals with array<P>
type specifiers as they refer to arrays as a whole. <P>
<P>
This proposal is consistent with <A HREF="iss337.htm">SYMBOL-MACROLET-DECLARE:ALLOW</A> and<P>
DECLARATION-SCOPE:LEXICAL.<P>
<P>
<B>Current practice:<P>
</B><P>
???<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
TBS<P>
<P>
<B>Cost to Users:<P>
</B><P>
Probably none; while this is technically a change, code that declares<P>
an array to contain one thing and depends on it containing something<P>
else is blatantly buggy.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Users will continue to expect declaration syntax to be more useful<P>
than it really is.<P>
<P>
<B>Performance impact:<P>
</B><P>
None.<P>
<P>
<B>Benefits:<P>
</B><P>
Array type declarations will behave in a more useful and intuitive way.<P>
<P>
<B>Aesthetics:<P>
</B><P>
Improved because the meaning of type declarations will coincide more<P>
clearly with their appearance.<P>
<P>
<B>Discussion:<P>
</B><P>
Pierson and Pitman support this proposal.<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>