Input Filtering and Mapping

We can use mapcan to both filter input and map input values to intermediate values for the application.

A key point is that we are not trying to compute the final answer, but to set up the inputs for another function to compute the final answer.

Suppose that we want to count the number of z's in an input list. We could map a z to a 1, which must be (1) for mapcan; anything else will map to () or nil.


(defun testforz (item)
  (if (eq item 'z)    ; if it is a z
      (list 1)        ;   emit 1    (map)
      '()) )          ;   else emit nothing
                      ;             (filter)

>(mapcan 'testforz '(z m u l e z r u l e z))

(1 1 1)

Contents    Page-10    Prev    Next    Page+10    Index