...
We will call this style of accumulation a Reverse Accumulation algorithm because the result is being accumulated as one "reverses" back out of the data structure.
Code Block |
---|
;; return the largest positive number in a list of numbers or zero if there are no positive values.
(define (get_largest_pos lon)
(cond
[(empty? lon) 0]
[(cons? lon)
(local
[(define acc (get_largest_pos (rest lon)))]
(if (> (first lon) acc) (first lon) acc))])) |
Here we can see that the accumulated value is just the largest value from the rest of the list at any given point.
(more coming...)
Forward accumulation
...