Lecture overview -- Keyboard shortcut: 'u'  Previous page: The reduction functions -- Keyboard shortcut: 'p'  Next page: Zipping -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 29 : 35
Programming Paradigms
Recursion and Higher-order Functions
Accumulation

It is not satisfactory that we cannot reduce the empty list

We remedy the problem by passing an extra parameter to the reduction functions

We call this variant of the reduction functions for accumulation

c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/reduction.scmThe function accumulate-right.

The recursive pattern is similar to the pattern of reduce-right.

Expression

Value

(accumulate-right - 0 '())
0
(accumulate-right - 0 '(1 2 3 4 5))
3
(accumulate-right append '()
  (list (list 1 2 3) (list 'a 'b 'c)))
(1 2 3 a b c)

Examples of right accumulations. The first row illustrates that we can accumulate the empty list. The second and third rows are similar to the second and third rows in Table 15.1.