SICP Accumulation Function

In the structure and interpretation of computer programs (SICP) Section 2.2.3, several functions are defined using:

(accumulate cons nil 
  (filter pred
         (map op sequence)))

Two examples that use this work on a list of fibonacci numbers, even-fibsand list-fib-squares.

The accumulation, filtering and display functions are also defined in section 2.2. The part that bothers me is why the authors included here accumulate. accumulateaccepts 3 parameters:

  • Binary Function Used

  • The initial value used as the right-most parameter for the function

  • The list to which the function will be applied.

An example of applying savings to a list using a definition in a book:

    (accumulate cons nil (list 1 2 3))
    => (cons 1 (cons 2 (cons 3 nil)))
    => (1 2 3)

, (accumulate cons nil some-list) some-list, (filter pred (map op sequence)) .

accumulate, ?

+3
1

, accumulate , "consing elements " , " " , " ". , .

( : , , , , filter accumulate , , .)

+5

Source: https://habr.com/ru/post/1763887/


All Articles