[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: MAPPING-DESTRUCTIVE-INTERACTION (Version 1)



Issue:        MAPPING-DESTRUCTIVE-INTERACTION
References:   MAPCAR, MAPLIST, ... (p128);
	      DOLIST (p126); MAPHASH (p285); 
	      DO-SYMBOLS, DO-EXTERNAL-SYMBOLS, DO-ALL-SYMBOLS (pp187-188);
	      All functions using :TEST	      
Category:     CLARIFICATION
Edit history: 07-Mar-88, Version 1 by Pitman
Status:	      For Internal Discussion

Problem Description:

 The interaction of mapping functions and DOLIST with destructive
 operations on the list being operated on is unclear. For example,
 if you destructively modify some tail of a list being mapped down,
 does that affect the mapping process?

Proposal (MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE):

 Document the fact that it is an error for code run by a 
 "structure traversing" operation to destructively modify the
 set of things being traversed while the traversal operation is
 going on.

Test Case:

 (LET* ((L (LIST 'A 'B 'C)) (LL L) (I 0))
   (DOLIST (FOO L)
     (INCF I)
     (IF (EQ FOO 'B)
	 (SETF (CDR LL) NIL)
	 (POP LL)))
   (LIST I L)) might return (2 (A B)) or (3 (A B)), for example.

Rationale:

 The likelihood that the user will want to destructively alter a structure
 while it is being traversed is low. The likelihood that such code would
 be readable and maintainable is also low. The likelihood that a compiler
 could do some interesting optimization if this point were not pinned down
 is high enough to be the overriding consideration in this case.

Current Practice:

 The Symbolics implementation of DOLIST returns (3 (A B)) for the test case.

Cost to Implementors:

  None. This simply makes the status quo explicit.

Cost to Users:

  Technically none. People who were mistakenly assuming that CLtL guaranteed
  things which it does not might be inclined to rewrite their code in a more
  portable way.

Cost of Non-Adoption:

  Users would be less informed.

Benefits:

  users would be more informed.

Aesthetics:

  Some might say it would be clearer to define this one way or the other, but
  advocates of both camps exist and their arguments are fairly symmetric.
  In any case, since this is a proposal to preserve the status quo, it has no
  major impact on aesthetics.

Discussion:

  This idea for this proposal was suggested by the Japanese community.
  Pitman drafted the formal proposal and supports 
  MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE.