Next: , Previous: , Up: vectors fold   [Index]


24.7.2 Folding over subvectors

Function: %subvector-fold-left combine knil vec start past
Function: %subvector-fold-right combine knil vec start past
Macro: subvector-fold-left combine knil S
Macro: subvector-fold-right combine knil S

Fold combine over each item of the selected subvector, return the return value of the last evaluated call to combine; if the selected subvector is empty, the return value is knil. The left–fold operator builds the return value as:

(combine
  (combine
        ...
        (combine
           (combine
              (vector-ref vec start)
              knil)
           (vector-ref vec (+ start 1)))
        ...
    (vector-ref vec (- past 2)))
    ...
  (vector-ref vec (- past 1)))

the right–fold iterator builds the return value as:

(combine
  (vector-ref vec start
  (combine
    (vector-ref vec (+ start 1))
    ...
      (combine
        (vector-ref vec (- past 3))
        (combine
           (vector-ref vec (- past 2))
           (combine
              (vector-ref vec (- past 1))
              knil)))))