concept-tests.tex 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. % -*- Mode: TeX -*-
  2. %% Rules about Test Functions
  3. \beginsubsection{Satisfying a Two-Argument Test}
  4. \DefineSection{SatisfyingTheTwoArgTest}
  5. When an \term{object} $O$ is being considered iteratively
  6. against each \term{element} $E\sub i$
  7. of a \term{sequence} $S$
  8. by an \term{operator} $F$ listed in \thenextfigure,
  9. it is sometimes useful to control the way in which the presence of $O$
  10. is tested in $S$ is tested by $F$.
  11. This control is offered on the basis of a \term{function} designated with
  12. either a \kwd{test} or \kwd{test-not} \term{argument}.
  13. %!!! Sandra wonders if this table is complete.
  14. \displaythree{Operators that have Two-Argument Tests to be Satisfied}{
  15. adjoin&nset-exclusive-or&search\cr
  16. assoc&nsublis&set-difference\cr
  17. count&nsubst&set-exclusive-or\cr
  18. delete&nsubstitute&sublis\cr
  19. find&nunion&subsetp\cr
  20. intersection&position&subst\cr
  21. member&pushnew&substitute\cr
  22. mismatch&rassoc&tree-equal\cr
  23. nintersection&remove&union\cr
  24. nset-difference&remove-duplicates&\cr
  25. }
  26. The object $O$ might not be compared directly to $E\sub i$.
  27. If a \kwd{key} \term{argument} is provided,
  28. it is a \term{designator} for a \term{function} of one \term{argument}
  29. to be called with each $E\sub i$ as an \term{argument},
  30. and \term{yielding} an \term{object} $Z\sub i$ to be used for comparison.
  31. (If there is no \kwd{key} \term{argument}, $Z\sub i$ is $E\sub i$.)
  32. % Added per Barmar. -kmp 16-Feb-92
  33. The \term{function} designated by \thekeyarg{key} is never called on $O$ itself.
  34. However, if the function operates on multiple sequences
  35. (\eg as happens in \funref{set-difference}), $O$
  36. will be the result of calling the \kwd{key} function on an
  37. \term{element} of the other sequence.
  38. A \kwd{test} \term{argument}, if supplied to $F$,
  39. is a \term{designator} for a \term{function}
  40. of two \term{arguments}, $O$ and $Z\sub i$.
  41. An $E\sub i$ is said (or, sometimes, an $O$ and an $E\sub i$ are said)
  42. to \newterm{satisfy the test}
  43. if this \kwd{test} \term{function} returns a \term{generalized boolean} representing
  44. \term{true}.
  45. A \kwd{test-not} \term{argument}, if supplied to $F$,
  46. is \term{designator} for a \term{function}
  47. of two \term{arguments}, $O$ and $Z\sub i$.
  48. An $E\sub i$ is said (or, sometimes, an $O$ and an $E\sub i$ are said)
  49. to \newterm{satisfy the test}
  50. if this \kwd{test-not} \term{function}
  51. returns a \term{generalized boolean} representing \term{false}.
  52. If neither a \kwd{test} nor a \kwd{test-not} \term{argument} is supplied,
  53. it is as if a \kwd{test} argument of \f{\#'eql} was supplied.
  54. The consequences are unspecified if both a \kwd{test} and a \kwd{test-not} \term{argument}
  55. are supplied in the same \term{call} to $F$.
  56. \beginsubsubsection{Examples of Satisfying a Two-Argument Test}
  57. \code
  58. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equal)
  59. \EV (foo bar "BAR" "foo" "bar")
  60. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'equalp)
  61. \EV (foo bar "BAR" "bar")
  62. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string-equal)
  63. \EV (bar "BAR" "bar")
  64. (remove "FOO" '(foo bar "FOO" "BAR" "foo" "bar") :test #'string=)
  65. \EV (BAR "BAR" "foo" "bar")
  66. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'eql)
  67. \EV (1)
  68. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test-not #'=)
  69. \EV (1 1.0 #C(1.0 0.0))
  70. (remove 1 '(1 1.0 #C(1.0 0.0) 2 2.0 #C(2.0 0.0)) :test (complement #'=))
  71. \EV (1 1.0 #C(1.0 0.0))
  72. (count 1 '((one 1) (uno 1) (two 2) (dos 2)) :key #'cadr) \EV 2
  73. (count 2.0 '(1 2 3) :test #'eql :key #'float) \EV 1
  74. (count "FOO" (list (make-pathname :name "FOO" :type "X")
  75. (make-pathname :name "FOO" :type "Y"))
  76. :key #'pathname-name
  77. :test #'equal)
  78. \EV 2
  79. \endcode
  80. \endsubsubsection%{Examples of Satisfying a Two-Argument Test}
  81. \endsubsection%{Satisfying a Two-Argument Test}
  82. \beginsubsection{Satisfying a One-Argument Test}
  83. \DefineSection{SatisfyingTheOneArgTest}
  84. When using one of the \term{functions} in \thenextfigure,
  85. the elements $E$ of a \term{sequence} $S$ are filtered
  86. not on the basis of the presence or absence of an object $O$
  87. under a two \term{argument} \term{predicate},
  88. as with the \term{functions} described in \secref\SatisfyingTheTwoArgTest,
  89. but rather on the basis of a one \term{argument} \term{predicate}.
  90. %!!! KMP wonders if this table is complete.
  91. \displaythree{Operators that have One-Argument Tests to be Satisfied}{
  92. assoc-if&member-if&rassoc-if\cr
  93. assoc-if-not&member-if-not&rassoc-if-not\cr
  94. count-if&nsubst-if&remove-if\cr
  95. count-if-not&nsubst-if-not&remove-if-not\cr
  96. delete-if&nsubstitute-if&subst-if\cr
  97. delete-if-not&nsubstitute-if-not&subst-if-not\cr
  98. find-if&position-if&substitute-if\cr
  99. find-if-not&position-if-not&substitute-if-not\cr
  100. }
  101. The element $E\sub i$ might not be considered directly.
  102. If a \kwd{key} \term{argument} is provided,
  103. it is a \term{designator} for a \term{function} of one \term{argument}
  104. to be called with each $E\sub i$ as an \term{argument},
  105. and \term{yielding} an \term{object} $Z\sub i$ to be used for comparison.
  106. (If there is no \kwd{key} \term{argument}, $Z\sub i$ is $E\sub i$.)
  107. \term{Functions} defined in this specification and having a name that
  108. ends in ``\f{-if}'' accept a first \term{argument} that is a \term{designator} for a
  109. \term{function} of one \term{argument}, $Z\sub i$.
  110. An $E\sub i$ is said to \newterm{satisfy the test} if this \kwd{test} \term{function}
  111. returns a \term{generalized boolean} representing \term{true}.
  112. \term{Functions} defined in this specification and having a name that
  113. ends in ``\f{-if-not}'' accept a first \term{argument} that is a \term{designator} for a
  114. \term{function} of one \term{argument}, $Z\sub i$.
  115. An $E\sub i$ is said to \newterm{satisfy the test} if this \kwd{test} \term{function}
  116. returns a \term{generalized boolean} representing \term{false}.
  117. \beginsubsubsection{Examples of Satisfying a One-Argument Test}
  118. \code
  119. (count-if #'zerop '(1 #C(0.0 0.0) 0 0.0d0 0.0s0 3)) \EV 4
  120. (remove-if-not #'symbolp '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
  121. \EV (A B C D E F)
  122. (remove-if (complement #'symbolp) '(0 1 2 3 4 5 6 7 8 9 A B C D E F))
  123. \EV (A B C D E F)
  124. (count-if #'zerop '("foo" "" "bar" "" "" "baz" "quux") :key #'length)
  125. \EV 3
  126. \endcode
  127. \endsubsubsection%{Examples of Satisfying a One-Argument Test}
  128. \endsubsection%{Satisfying a One-Argument Test}