DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) SRFI-1 Fold and Map

Info Catalog (guile.info.gz) SRFI-1 Length Append etc (guile.info.gz) SRFI-1 (guile.info.gz) SRFI-1 Filtering and Partitioning
 
 39.3.5 Fold, Unfold & Map
 -------------------------
 
  -- Scheme Procedure: fold kons knil lst1 lst2 ...
      Fold the procedure KONS across all elements of LST1, LST2, ....
      Produce the result of
 
      `(KONS EN1 EN2 ... (KONS E21 E22 (KONS E11 E12 KNIL)))',
 
      if ENM are the elements of the lists LST1, LST2, ....
 
  -- Scheme Procedure: fold-right kons knil lst1 lst2 ...
      Similar to `fold', but applies KONS in right-to-left order to the
      list elements, that is:
 
      `(KONS E11 E12(KONS E21 E22  ... (KONS EN1 EN2 KNIL)))',
 
  -- Scheme Procedure: pair-fold kons knil lst1 lst2 ...
      Like `fold', but apply KONS to the pairs of the list instead of
      the list elements.
 
  -- Scheme Procedure: pair-fold-right kons knil lst1 lst2 ...
      Like `fold-right', but apply KONS to the pairs of the list instead
      of the list elements.
 
  -- Scheme Procedure: reduce f ridentity lst
      `reduce' is a variant of `reduce'.  If LST is `()', RIDENTITY is
      returned.  Otherwise, `(fold (car LST) (cdr LST))' is returned.
 
  -- Scheme Procedure: reduce-right f ridentity lst
      This is the `fold-right' variant of REDUCE.
 
  -- Scheme Procedure: unfold p f g seed [tail-gen]
      `unfold' is defined as follows:
 
           (unfold p f g seed) =
              (if (p seed) (tail-gen seed)
                  (cons (f seed)
                        (unfold p f g (g seed))))
 
     P
           Determines when to stop unfolding.
 
     F
           Maps each seed value to the corresponding list element.
 
     G
           Maps each seed value to next seed valu.
 
     SEED
           The state value for the unfold.
 
     TAIL-GEN
           Creates the tail of the list; defaults to `(lambda (x) '())'.
 
      G produces a series of seed values, which are mapped to list
      elements by F.  These elements are put into a list in
      left-to-right order, and P tells when to stop unfolding.
 
  -- Scheme Procedure: unfold-right p f g seed [tail]
      Construct a list with the following loop.
 
           (let lp ((seed seed) (lis tail))
              (if (p seed) lis
                  (lp (g seed)
                      (cons (f seed) lis))))
 
     P
           Determines when to stop unfolding.
 
     F
           Maps each seed value to the corresponding list element.
 
     G
           Maps each seed value to next seed valu.
 
     SEED
           The state value for the unfold.
 
     TAIL-GEN
           Creates the tail of the list; defaults to `(lambda (x) '())'.
 
 
  -- Scheme Procedure: map f lst1 lst2 ...
      Map the procedure over the list(s) LST1, LST2, ... and return a
      list containing the results of the procedure applications.  This
      procedure is extended with respect to R5RS, because the argument
      lists may have different lengths.  The result list will have the
      same length as the shortest argument lists.  The order in which F
      will be applied to the list element(s) is not specified.
 
  -- Scheme Procedure: for-each f lst1 lst2 ...
      Apply the procedure F to each pair of corresponding elements of
      the list(s) LST1, LST2, ....  The return value is not specified.
      This procedure is extended with respect to R5RS, because the
      argument lists may have different lengths.  The shortest argument
      list determines the number of times F is called.  F will be
      applied to the list elements in left-to-right order.
 
 
  -- Scheme Procedure: append-map f lst1 lst2 ...
  -- Scheme Procedure: append-map! f lst1 lst2 ...
      Equivalent to
 
           (apply append (map f clist1 clist2 ...))
 
      and
 
           (apply append! (map f clist1 clist2 ...))
 
      Map F over the elements of the lists, just as in the `map'
      function. However, the results of the applications are appended
      together to make the final result. `append-map' uses `append' to
      append the results together; `append-map!' uses `append!'.
 
      The dynamic order in which the various applications of F are made
      is not specified.
 
  -- Scheme Procedure: map! f lst1 lst2 ...
      Linear-update variant of `map' - `map!' is allowed, but not
      required, to alter the cons cells of LST1 to construct the result
      list.
 
      The dynamic order in which the various applications of F are made
      is not specified. In the n-ary case, LST2, LST3, ... must have at
      least as many elements as LST1.
 
  -- Scheme Procedure: pair-for-each f lst1 lst2 ...
      Like `for-each', but applies the procedure F to the pairs from
      which the argument lists are constructed, instead of the list
      elements.  The return value is not specified.
 
  -- Scheme Procedure: filter-map f lst1 lst2 ...
      Like `map', but only results from the applications of F which are
      true are saved in the result list.
 
Info Catalog (guile.info.gz) SRFI-1 Length Append etc (guile.info.gz) SRFI-1 (guile.info.gz) SRFI-1 Filtering and Partitioning
automatically generated byinfo2html