Scheme - How do I loop an anonymous function?
<p>I have been trying to convert a normal function into a higher order function that does the same thing. The function is supposed to take a operator as a argument and then apply that operator to each and every element in a list. For example if I choose the operator "+" it would return the sum of all the elements in a list. </p>

<p>Normal version of function:</p>

<pre><code>(define (accumulate proc id lst)
  (cond ((null? lst) id)
    ((eqv? (cdr lst) '()) (car lst))
    (else (proc (car lst) (accumulate proc id (cdr lst))))))
</code></pre>

<p>Higher order version of function (incomplete):</p>

<pre><code>(define (acc-proc proc id)
(lambda (lst)
(cond ((null? lst) id)
      ((null? (cdr lst)) (car lst))
      (else 
</code></pre>

<p>In the normal function I am using a recursive call to loop it but I can't loop the higher order function because it doesn't have lst as an argument. Instead the argument lst is in the anonymous lambda procedure.</p>

<p>I am new to Scheme so forgive me if my solutions are bad. Maybe there is a better way to do this without looping? I have no idea what to put into that else statement...</p>