GNU Info

Info Node: (librep.info)Mapping Functions

(librep.info)Mapping Functions


Prev: Calling Functions Up: Functions
Enter node , (file) or (file)node

Mapping Functions
-----------------

   A "mapping function" applies a function to each of a collection of
objects. `librep' currently has two mapping functions, `mapcar' and
`mapc'.

 - Function: mapcar function list
     Each element of LIST is individually applied to the function
     FUNCTION. The values returned are made into a new list which is
     returned.

     The FUNCTION must accept a single argument value.

          (mapcar 1+ '(1 2 3 4 5))
              => (2 3 4 5 6)

 - Function: mapc function list
     Similar to `mapcar' except that the values returned when each
     element is applied to the function FUNCTION are discarded. The
     value returned is undefined.

     This function is generally used where the side effects of calling
     the function are the important thing, not the results. It is often
     the most efficient way of traversing all items in a list, for
     example:

          (mapc (lambda (x)
                  (print x standard-error)) list)

   The two following functions are also mapping functions of a sort.
They are variants of the `delete' function (Note: Modifying Lists)
and use predicate functions to classify the elements of the list which
are to be deleted.

 - Function: delete-if predicate list
     This function is a variant of the `delete' function. Instead of
     comparing each element of LIST with a specified object, each
     element of LIST is applied to the predicate function PREDICATE. If
     it returns true then the element is destructively removed from
     LIST.

          (delete-if stringp '(1 "foo" 2 "bar" 3 "baz"))
              => (1 2 3)

 - Function: delete-if-not predicate list
     This function does the inverse of `delete-if'. It applies
     PREDICATE to each element of LIST, if it returns false then the
     element is destructively removed from the list.

          (delete-if-not stringp '(1 "foo" 2 "bar" 3 "baz"))
              => ("foo" "bar" "baz")

   The `filter' function is similar to `delete-if-not', except that the
original list isn't modified, a new list is created.

 - Function: filter predicate list
     Return a new list, consisting of the elements in LIST which the
     function PREDICATE returns true when applied to. This function is
     equivalent to:

          (mapcar nconc (mapcar (lambda (x)
                                  (and (PREDICATE x) (list x)))
                                LIST))


automatically generated by info2www version 1.2.2.9