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

139 lines
7.4 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 DISPLACED-ARRAY-PREDICATE 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/iss131_w.htm">
<LINK REL=UP HREF="../Issues/iss132.htm">
<LINK REL=NEXT HREF="../Issues/iss133_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/iss131_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss132.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss133_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DISPLACED-ARRAY-PREDICATE Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss132.htm">DISPLACED-ARRAY-PREDICATE</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A><P>
Related issues: <A HREF="iss003.htm">ADJUST-ARRAY-DISPLACEMENT</A><P>
<B>Category:</B> ADDITION<P>
<B>Edit history:</B> v1, 13 Feb 1991, Sandra Loosemore<P>
v2, 11 Mar 1991, Sandra Loosemore<P>
v3, 26 Mar 1991, Sandra Loosemore (amendment from meeting)<P>
<B>Status:</B> v3 (proposal ADD) accepted by X3J13, Mar 91<P>
<P>
<P>
<B>Problem description:<P>
</B><P>
There is no way to determine whether an array is displaced to another<P>
array. Having this information available would be helpful to some<P>
applications that want to dump and restore array contents, either to <P>
allow them to detect when sharing of displaced arrays is lost or to<P>
reconstruct the arrays in such a way that sharing is preserved.<P>
<P>
<B>Proposal (DISPLACED-ARRAY-PREDICATE:ADD):<P>
</B><P>
Add a function:<P>
<P>
<A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>ARRAY-DISPLACEMENT</B></A> &lt;array&gt; [Function]<P>
<P>
The &lt;array&gt; argument must be an array. If the array is a displaced<P>
array, two values are returned: the array to which it is displaced<P>
corresponding to the :DISPLACED-TO argument to <A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A>, and an<P>
integer corresponding to the :DISPLACED-INDEX-OFFSET argument to<P>
<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A>. If the array is not a displaced array, this function<P>
returns two values <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> and 0.<P>
<P>
If <A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>ARRAY-DISPLACEMENT</B></A> is called on an array for which a non-NIL<P>
object was provided as the :DISPLACED-TO argument to <A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> <P>
or <A REL=DEFINITION HREF="../Body/f_adjust.htm#adjust-array"><B>ADJUST-ARRAY</B></A>, it must return that object as its first value. <P>
It is implementation-dependent whether <A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>ARRAY-DISPLACEMENT</B></A> returns<P>
a non-NIL first value for any other array.<P>
<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>array-displacement</B></A> '#(1 2 3))<P>
=&gt; the values are not specified, but are probably <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> and 0 in many<P>
implementations.<P>
(<A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>array-displacement</B></A> (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> 2 :displaced-to '#1=#(1 2 3)))<P>
=&gt; (values #1# 0)<P>
<P>
<B>Rationale:<P>
</B><P>
Providing the function solves the problem.<P>
<P>
Some implementations implicitly displace some arrays. (For example,<P>
adjustable arrays might be represented as displaced arrays.) Permitting<P>
<A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>ARRAY-DISPLACEMENT</B></A> to return non-NIL for those arrays allows those<P>
implementations not to have to record some additional information <P>
in the array about whether an explicit :DISPLACED-TO was provided.<P>
<P>
<B>Current Practice:<P>
</B><P>
Lucid version 4.0 and Apple's Macintosh Common Lisp implement such<P>
a function, but call it DISPLACED-ARRAY-P.<P>
<P>
Symbolics has an ARRAY-DISPLACED-P predicate but it returns neither <P>
the array nor an index, just a <A REL=DEFINITION HREF="../Body/t_ban.htm#boolean"><B>boolean</B></A>.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
It's probably easy to add.<P>
<P>
<B>Cost to Users:<P>
</B><P>
None, this is a new feature.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Users can't do some kind of manipulations on displaced arrays in a <P>
portable way.<P>
<P>
<B>Performance impact:<P>
</B><P>
Probably none.<P>
<P>
<B>Benefits:<P>
</B><P>
The cost of non-adoption is avoided.<P>
<P>
<B>Esthetics:<P>
</B><P>
Looks OK to me.<P>
<P>
<B>Discussion:<P>
</B><P>
The addition of such a function was mentioned in the writeup for<P>
proposal <A HREF="iss003.htm">ADJUST-ARRAY-DISPLACEMENT</A> as something that had been<P>
considered at that time. I don't recall what the arguments were <P>
against it.<P>
<P>
A more extreme proposal would also define <A REL=DEFINITION HREF="../Body/f_ar_dis.htm#array-displacement"><B>ARRAY-DISPLACEMENT</B></A> as<P>
a <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> place, to allow these parameters of displaced arrays to <P>
be changed.<P>
<P>
The original name suggested for this function was DISPLACED-ARRAY-P.<P>
<P>
JonL notes:<P>
<P>
The reason Lucid has DISPLACED-ARRAY-P is that is the name Guy Steele<P>
gave it back it 6-Dec-85 -- the &quot;Clarifications&quot; and<P>
&quot;non-controversial ...&quot; lists. Quite possibly, it had been suggested<P>
already in the common-lisp@su-ai forum.<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>