286 lines
16 KiB
HTML
286 lines
16 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 DOTTED-LIST-ARGUMENTS 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/iss137_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss138.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss139_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/iss137_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss138.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss139_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue DOTTED-LIST-ARGUMENTS Writeup</H2>
|
|
|
|
<PRE><B>Forum:</B> Public Review<P>
|
|
<B>Issue:</B> <A HREF="iss138.htm">DOTTED-LIST-ARGUMENTS</A><P>
|
|
<B>References:</B> Loosemore's public review comment #10 (X3J13/92-1310)<P>
|
|
Pitman's public review comments #37, #38, #39<P>
|
|
(X3J13/92-2737, -2738, -2739)<P>
|
|
Issue APPEND-DOTTED (retracted)<P>
|
|
Issue APPEND-FIASCO (withdrawn)<P>
|
|
Issue APPEND-ATOM (withdrawn)<P>
|
|
Issue <A HREF="iss293.htm">REMF-DESTRUCTION-UNSPECIFIED</A> (passed)<P>
|
|
Issue <A HREF="iss209.htm">LAST-N</A> (passed)<P>
|
|
<B>Category:</B> CLARIFICATION, CHANGE<P>
|
|
<B>Edit history:</B> 23 Dec 1992, Version 1 by Loosemore<P>
|
|
04 Feb 1993, Version 2 by Loosemore (comments from Barmar)<P>
|
|
<B>Status:</B> Proposal CLARIFY passed (6+3)-2 on letter ballot 93-302.<P>
|
|
<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
The next-to-last paragraph on page 14-2 (in draft 12.24) says that<P>
|
|
functions that take list arguments should be prepared to signal an<P>
|
|
error if they receive dotted list arguments, except as explicitly<P>
|
|
stated otherwise. But many of the descriptions of the functions in<P>
|
|
chapter 14 do not explicitly state otherwise, where they clearly ought<P>
|
|
to. (In some cases, the "correct" behavior is implied by notes or<P>
|
|
examples, which are not binding parts of the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A>.) For example,<P>
|
|
surely the committee did not intend to make primitive accessors such<P>
|
|
as <A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> and <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> fail on dotted lists!<P>
|
|
<P>
|
|
Similarly, there are exceptions missing for the rule stated in the<P>
|
|
last paragraph on page 14-2 (the consequences are undefined if<P>
|
|
a circular list is passed). <P>
|
|
<P>
|
|
For the functions which operate on trees, there is a further problem.<P>
|
|
Some of the arguments are described as "objects", and others are<P>
|
|
described as "lists", which I think is incorrect -- an atomic tree<P>
|
|
argument should also be OK for functions such as <A REL=DEFINITION HREF="../Body/f_substc.htm#subst"><B>SUBST</B></A> and <A REL=DEFINITION HREF="../Body/f_sublis.htm#sublis"><B>SUBLIS</B></A>.<P>
|
|
The dotted-list prohibition should clearly not apply to the tree<P>
|
|
functions. But since tree functions recursively descend both the <P>
|
|
<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> and <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>cdr</B></A> chains of a cons, there should be a prohibition against<P>
|
|
circular tree <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> in the arguments to these functions, not<P>
|
|
just circular list <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A>.<P>
|
|
<P>
|
|
Finally, there is confusion about whether atoms may be considered<P>
|
|
degenerate dotted lists in some contexts.<P>
|
|
<P>
|
|
<P>
|
|
<B>Proposal (DOTTED-LIST-ARGUMENTS:CLARIFY):<P>
|
|
</B><P>
|
|
(1) Add to page 14-2 a third paragraph:<P>
|
|
<P>
|
|
Except as explicitly stated otherwise, for any standardized<P>
|
|
function that is required to be a tree, the consequences are<P>
|
|
undefined if that tree is circular.<P>
|
|
<P>
|
|
(2) Clarify that association lists, property lists, and lists<P>
|
|
that are treated as sequences must be proper lists.<P>
|
|
<P>
|
|
(3) Change the glossary definitions of "dotted list" and "list" to<P>
|
|
clarify that atoms are not considered dotted lists.<P>
|
|
<P>
|
|
(4) Clarify the nature of list arguments to the functions in chapter<P>
|
|
14, as follows:<P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A>, <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> and friends: the argument "x" is permitted to be dotted<P>
|
|
or circular.<P>
|
|
<P>
|
|
Rationale: These are primitive accessors.<P>
|
|
<P>
|
|
<P>
|
|
COPY-TREE: the argument "object" is a tree (not an object).<P>
|
|
<A REL=DEFINITION HREF="../Body/f_sublis.htm#sublis"><B>SUBLIS</B></A>, NSUBLIS: the "tree" argument is a tree (not a list).<P>
|
|
<A REL=DEFINITION HREF="../Body/f_substc.htm#subst"><B>SUBST</B></A> and friends: the "tree" argument is a tree (not a list).<P>
|
|
TREE-EQUAL: the arguments "object1" and "object2" are trees<P>
|
|
(not objects).<P>
|
|
<P>
|
|
Rationale: This makes all the tree functions consistent.<P>
|
|
<P>
|
|
<P>
|
|
COPY-LIST: the argument "list" may be dotted but not circular.<P>
|
|
<P>
|
|
Rationale: This is what CLtL said.<P>
|
|
<P>
|
|
<P>
|
|
LIST-LENGTH: the argument "list" may be circular but not dotted.<P>
|
|
<P>
|
|
Rationale: It's supposed to detect and return <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> for <P>
|
|
circular lists.<P>
|
|
<P>
|
|
<P>
|
|
POP: the "place" argument is permitted to evaluate to a dotted or<P>
|
|
circular list.<P>
|
|
PUSH: the "place" argument may evaluate to any object (not just <P>
|
|
a list).<P>
|
|
<P>
|
|
Rationale: This follows from the equivalences given in the notes.<P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_firstc.htm#first"><B>FIRST</B></A> and friends: the argument "list" may be dotted or circular.<P>
|
|
<P>
|
|
Rationale: These functions are commonly implemented as chains<P>
|
|
of <A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> and <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> operations.<P>
|
|
<P>
|
|
<P>
|
|
NTH: the argument "list" may be dotted or circular. Note that<P>
|
|
the references to the length of the argument list in the<P>
|
|
description are incorrect, since this concept doesn't make<P>
|
|
sense for dotted lists. The right thing to do is simply to <P>
|
|
define (<A REL=DEFINITION HREF="../Body/f_nth.htm#nth"><B>NTH</B></A> n list) = (<A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>CAR</B></A> (<A REL=DEFINITION HREF="../Body/f_nthcdr.htm#nthcdr"><B>NTHCDR</B></A> n list)).<P>
|
|
<P>
|
|
Rationale: The notes for <A REL=DEFINITION HREF="../Body/f_firstc.htm#first"><B>FIRST</B></A> and friends say that<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_firstc.htm#fifth"><B>FIFTH</B></A> x) == (<A REL=DEFINITION HREF="../Body/f_nth.htm#nth"><B>NTH</B></A> 4 x). This also makes <A REL=DEFINITION HREF="../Body/f_nth.htm#nth"><B>NTH</B></A> and <A REL=DEFINITION HREF="../Body/f_nthcdr.htm#nthcdr"><B>NTHCDR</B></A><P>
|
|
consistent.<P>
|
|
<P>
|
|
<P>
|
|
ENDP: the argument "list" may be dotted or circular.<P>
|
|
<P>
|
|
Rationale: This function only cares whether the argument is<P>
|
|
NIL/a cons/something else.<P>
|
|
<P>
|
|
<P>
|
|
NCONC: the last "list" argument may be any object. The remaining <P>
|
|
"lists" may be dotted but not circular.<P>
|
|
<P>
|
|
Rationale: This follows from the equivalence in the description<P>
|
|
(from issue <A HREF="iss293.htm">REMF-DESTRUCTION-UNSPECIFIED</A>).<P>
|
|
<P>
|
|
<P>
|
|
NRECONC: the argument "list1" must be a proper list.<P>
|
|
The argument "list2" can be any object (not just a list).<P>
|
|
(The example showing "list1" as a dotted <A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> is incorrect.)<P>
|
|
<P>
|
|
Rationale: This follows from the equivalence in the side effects<P>
|
|
section, which was added by issue <A HREF="iss293.htm">REMF-DESTRUCTION-UNSPECIFIED</A>. <P>
|
|
(<A REL=DEFINITION HREF="../Body/f_revers.htm#nreverse"><B>NREVERSE</B></A> is a <A REL=DEFINITION HREF="../Body/t_seq.htm#sequence"><B>sequence</B></A> <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A>.)<P>
|
|
<P>
|
|
<P>
|
|
APPEND: the last "list" argument may be any object.<P>
|
|
The remaining "lists" must be proper lists.<P>
|
|
<P>
|
|
Rationale: Allowing any object as the last argument came from<P>
|
|
CLtL. The inconsistency of the remaining arguments compared to <P>
|
|
<A REL=DEFINITION HREF="../Body/f_nconc.htm#nconc"><B>NCONC</B></A> was a deliberate decision by X3J13 (issues APPEND-DOTTED, etc).<P>
|
|
<P>
|
|
<P>
|
|
REVAPPEND: the argument "list1" must be a proper list.<P>
|
|
The argument "list2" can be any object (not just a list).<P>
|
|
(The example showing "list1" as a dotted <A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> is incorrect.)<P>
|
|
<P>
|
|
Rationale: This follows from the equivalence in the notes section.<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_revers.htm#reverse"><B>REVERSE</B></A> is a <A REL=DEFINITION HREF="../Body/t_seq.htm#sequence"><B>sequence</B></A> <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A>.)<P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_butlas.htm#butlast"><B>BUTLAST</B></A>, NBUTLAST: the argument "list" may be dotted but not <P>
|
|
circular. (The functions should complement <A REL=DEFINITION HREF="../Body/f_last.htm#last"><B>LAST</B></A> by counting <P>
|
|
conses, not elements.)<P>
|
|
<P>
|
|
Rationale: An obvious identity is<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_butlas.htm#butlast"><B>BUTLAST</B></A> list n) == (<A REL=DEFINITION HREF="../Body/f_ldiffc.htm#ldiff"><B>LDIFF</B></A> list (<A REL=DEFINITION HREF="../Body/f_last.htm#last"><B>LAST</B></A> list n))<P>
|
|
The intent of issue <A HREF="iss209.htm">LAST-N</A> was clearly to make <A REL=DEFINITION HREF="../Body/f_last.htm#last"><B>LAST</B></A> and <A REL=DEFINITION HREF="../Body/f_butlas.htm#butlast"><B>BUTLAST</B></A><P>
|
|
complementary.<P>
|
|
<P>
|
|
<P>
|
|
LAST: the argument "list" may be dotted but not circular.<P>
|
|
<P>
|
|
Rationale: This follows from the definition in the notes section.<P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_ldiffc.htm#ldiff"><B>LDIFF</B></A>, TAILP: the "list" argument may be dotted. The "sublist"<P>
|
|
argument may be any object (not just a list). Both arguments may<P>
|
|
be circular lists only if (<A REL=DEFINITION HREF="../Body/f_ldiffc.htm#tailp"><B>TAILP</B></A> sub-list list) is true.<P>
|
|
<P>
|
|
Rationale: This is already stated for <A REL=DEFINITION HREF="../Body/f_ldiffc.htm#tailp"><B>TAILP</B></A> and the two functions<P>
|
|
are clearly related.<P>
|
|
<P>
|
|
<P>
|
|
NTHCDR: the "list" argument may be dotted or circular.<P>
|
|
<P>
|
|
Rationale: The examples show use on a dotted list, and the <P>
|
|
function will clearly still terminate if passed a circular list.<P>
|
|
<P>
|
|
<P>
|
|
REST: the "list" argument is permitted to be dotted or circular.<P>
|
|
<P>
|
|
Rationale: compatibility with <A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> and <A REL=DEFINITION HREF="../Body/f_firstc.htm#first"><B>FIRST</B></A>.<P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/a_member.htm#member"><B>MEMBER</B></A> and friends: the "list" argument must be a proper list.<P>
|
|
<A REL=DEFINITION HREF="../Body/f_isec_.htm#intersection"><B>INTERSECTION</B></A>, NINTERSECTION: the "list-1" and "list-2" arguments<P>
|
|
must be proper lists.<P>
|
|
ADJOIN: the "list" argument must be a proper list.<P>
|
|
PUSHNEW: the "place" argument must evaluate to a proper list.<P>
|
|
<A REL=DEFINITION HREF="../Body/f_set_di.htm#set-difference"><B>SET-DIFFERENCE</B></A>, NSET-DIFFERENCE: the "list-1" and "list-2" <P>
|
|
arguments must be proper lists.<P>
|
|
<A REL=DEFINITION HREF="../Body/f_set_ex.htm#set-exclusive-or"><B>SET-EXCLUSIVE-OR</B></A>, NSET-EXCLUSIVE-OR: the "list-1" and "list-2" <P>
|
|
arguments must be proper lists.<P>
|
|
SUBSETP: the "list1" and "list2" arguments must be proper lists.<P>
|
|
<A REL=DEFINITION HREF="../Body/f_unionc.htm#union"><B>UNION</B></A>, NUNION: the "list1" and "list2" arguments must be proper lists.<P>
|
|
<P>
|
|
Rationale: This makes all the functions that operate on lists as<P>
|
|
sets consistent. <P>
|
|
<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_mapc_.htm#mapc"><B>MAPC</B></A> and friends: the "list" arguments must be proper lists.<P>
|
|
<P>
|
|
Rationale: The description makes clear that the lists are treated<P>
|
|
as sequences.<P>
|
|
<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B><P>
|
|
Loosemore thinks the only item that is likely to cause compatibility<P>
|
|
problems is explicitly requiring <A REL=DEFINITION HREF="../Body/f_butlas.htm#butlast"><B>BUTLAST</B></A> to work on dotted lists:<P>
|
|
currently at least CMU CL and AKCL signal an error, but it works<P>
|
|
in Lucid.<P>
|
|
<P>
|
|
<P>
|
|
<B>Cost to implementors:<P>
|
|
</B><P>
|
|
This proposal should probably make it easier for implementors to do<P>
|
|
the right thing. Given the previous addition of the requirement that<P>
|
|
implementations "should be prepared to signal" errors about dotted lists<P>
|
|
and tighter restrictions about signalling TYPE-ERRORs for incorrect<P>
|
|
arguments, all implementors probably need to reexamine the definitions<P>
|
|
of these functions for conformance anyway.<P>
|
|
<P>
|
|
<P>
|
|
<B>Cost to users:<P>
|
|
</B><P>
|
|
There may be a few currently working programs that will stop working.<P>
|
|
<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
This whole problem is messy to deal with.<P>
|
|
<P>
|
|
<P>
|
|
<B>Editorial impact:<P>
|
|
</B><P>
|
|
Substantial, but it needs to be done to correct obvious errors.<P>
|
|
<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Loosemore notes that there are a few more functions which could <P>
|
|
reasonably be defined to work on atoms as degenerate dotted lists<P>
|
|
(notably, <A REL=DEFINITION HREF="../Body/f_ldiffc.htm#tailp"><B>TAILP</B></A> and <A REL=DEFINITION HREF="../Body/f_ldiffc.htm#ldiff"><B>LDIFF</B></A>) but that current practice is to signal<P>
|
|
an error, so the proposal does not include these.<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<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>
|