concept-destruction.tex 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. % -*- Mode: TeX -*-
  2. % Destructive Operations
  3. \issue{DESTRUCTIVE-OPERATIONS:SPECIFY}
  4. \beginsubsection{Modification of Literal Objects}
  5. The consequences are undefined if \term{literal} \term{objects}
  6. are destructively modified. For this purpose, the following operations
  7. are considered \term{destructive}:
  8. \beginlist
  9. \itemitem{\typeref{random-state}}
  10. % Using it as an argument to the function RANDOM.
  11. Using it as an \term{argument} to \thefunction{random}.
  12. \itemitem{\typeref{cons}}
  13. % Altering or destructively modifying the CAR or CDR of the cons.
  14. Changing the \term{car}\meaning{1} or \term{cdr}\meaning{1} of the \term{cons},
  15. or performing a \term{destructive} operation on an \term{object} which is either
  16. the \term{car}\meaning{2} or the \term{cdr}\meaning{2} of the \term{cons}.
  17. \itemitem{\typeref{array}}
  18. % Altering or destructively modifying any array element;
  19. % changing the fill pointer, dimensions, or displacement of
  20. % the array (regardless of whether the array is actually adjustable);
  21. % or altering the contents of any array that is displaced to this array
  22. % or that otherwise shares its contents with this array.
  23. Storing a new value into some element of the \term{array},
  24. or performing a \term{destructive} operation
  25. on an \term{object} that is already such an \term{element}.
  26. Changing the \term{fill pointer}, \term{dimensions}, or displacement of
  27. the \term{array} (regardless of whether the \term{array} is \term{actually adjustable}).
  28. Performing a \term{destructive} operation on another \term{array}
  29. that is displaced to the \term{array} or that otherwise shares its contents
  30. with the \term{array}.
  31. \itemitem{\typeref{hash-table}}
  32. % Altering or destructively modifying any key or its corresponding
  33. % value, or adding or removing entries from the hash table.
  34. Performing a \term{destructive} operation on any \term{key}.
  35. Storing a new \term{value}\meaning{4} for any \term{key},
  36. or performing a \term{destructive} operation
  37. on any \term{object} that is such a \term{value}.
  38. Adding or removing entries from the \term{hash table}.
  39. \itemitem{\typeref{structure-object}}
  40. % Altering or destructively modifying the contents of any slot.
  41. Storing a new value into any slot,
  42. or performing a \term{destructive} operation on an \term{object}
  43. that is the value of some slot.
  44. \itemitem{\typeref{standard-object}}
  45. % Altering or destructively modifying the contents of any slot, or
  46. % changing the class of the object.
  47. Storing a new value into any slot,
  48. or performing a \term{destructive} operation on an \term{object}
  49. that is the value of some slot.
  50. Changing the class of the \term{object} (\eg using \thefunction{change-class}).
  51. \itemitem{\typeref{readtable}}
  52. % Altering the readtable-case; altering the syntax type of any
  53. % character in this readtable; altering the reader macro function
  54. % associated with any character in this readtable; or altering the
  55. % reader macro functions associated with characters defined as
  56. % dispatching macro characters in this readtable.
  57. Altering the \term{readtable case}.
  58. Altering the syntax type of any character in this readtable.
  59. Altering the \term{reader macro function} associated with any \term{character}
  60. in the \term{readtable}, or altering the \term{reader macro functions}
  61. associated with \term{characters} defined as \term{dispatching macro characters}
  62. in the \term{readtable}.
  63. \itemitem{\typeref{stream}}
  64. % Performing I/O operations on the stream, or closing the stream.
  65. Performing I/O operations on the \term{stream},
  66. or \term{closing} the \term{stream}.
  67. \itemitem{All other standardized types}
  68. [This category includes, for example, \typeref{character},
  69. \typeref{condition},
  70. \typeref{function},
  71. \typeref{method-combination},
  72. \typeref{method},
  73. \typeref{number},
  74. \typeref{package},
  75. \typeref{pathname},
  76. \typeref{restart},
  77. and \typeref{symbol}.]
  78. % (including number, character, symbol, package, pathname, function,
  79. % method, method-combination, condition, restart)
  80. % There are no destructive operations defined on these data types.
  81. There are no \term{standardized} \term{destructive} operations
  82. defined on \term{objects} of these \term{types}.
  83. \endlist
  84. \endsubsection%{Modification of Literal Objects}
  85. \endissue{DESTRUCTIVE-OPERATIONS:SPECIFY}
  86. \beginsubsection{Transfer of Control during a Destructive Operation}
  87. %%% This text used to just apply to SORT.
  88. %%% KMP modified it to generalize from errors to arbitrary transfer
  89. %%% of control, since not just errors can cause this. Consider:
  90. %%% (prog foo ((a (list 1 2 3 4 5 6 7 8 9 10)))
  91. %%% (sort a #'(lambda (x y)
  92. %%% (if (zerop (random 5)) (return-from foo a) (> x y)))))
  93. %%% Barrett suggested further generalizing it for other the sake of
  94. %%% application to other destructive operations.
  95. %%% KMP agreed since it's true that things are ill-defined whether we say
  96. %%% it or not, so we might as well say it explicitly.
  97. %%%
  98. %%% Original text from SORT:
  99. %%% %% 14.4.0 8
  100. %%% Should execution of the \param{key} or the \param{predicate}
  101. %%% cause an error,
  102. %%% the state of the \param{sequence} being sorted is
  103. %%% undefined. However, if the error is corrected, the sort will
  104. %%% proceed correctly.
  105. Should a transfer of control out of a \term{destructive} operation occur
  106. (\eg due to an error) the state of the \param{object} being modified is
  107. \term{implementation-dependent}.
  108. \beginsubsubsection{Examples of Transfer of Control during a Destructive Operation}
  109. The following examples illustrate some of the many ways in which the
  110. \term{implementation-dependent} nature of the modification can manifest
  111. itself.
  112. \code
  113. (let ((a (list 2 1 4 3 7 6 'five)))
  114. (ignore-errors (sort a #'<))
  115. a)
  116. \EV (1 2 3 4 6 7 FIVE)
  117. \OV (2 1 4 3 7 6 FIVE)
  118. \OV (2)
  119. (prog foo ((a (list 1 2 3 4 5 6 7 8 9 10)))
  120. (sort a #'(lambda (x y) (if (zerop (random 5)) (return-from foo a) (> x y)))))
  121. \EV (1 2 3 4 5 6 7 8 9 10)
  122. \OV (3 4 5 6 2 7 8 9 10 1)
  123. \OV (1 2 4 3)
  124. \endcode
  125. \endsubsubsection%{Examples of Transfer of Control during a Destructive Operation}
  126. \endsubsection%{Transfer of Control during a Destructive Operation}