[plt-scheme] trying to make a function that adds a list

From: trista (tstanton44 at gmail.com)
Date: Sat Feb 17 14:23:40 EST 2007

The assignment is as follows:

Write a Scheme functin that accepts an accumulating functin
(summation, product) and a list of numbers and returns the
accumulation of the operation on each element of the list.  If the
list '(1 2 3 4 ) was supplied and an operatin "sum" that adds two
elements, the function should return the sum of the list.

I figure that I should start by writing a function that builds the

(define (doall fn l)
  (if (null? (cdr l)
          (list (fn(car l)))
          (append (process_all fn(cdr l))(list fn(car l))))))

But I am getting an error when I try to run it:

if: bad syntax (has 1 part after keyword) in: (if (null? (cdr l) (list
(fn (car l))) (append (process_all fn (cdr l)) (list fn (car l)))))

Can somebody help me?


Posted on the users mailing list.