[plt-scheme] Adding a list

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sat Feb 17 16:02:03 EST 2007

Teresa, I suggest you open your file in DrScheme, select that
function, and run "Reindent" from the "Scheme" menu.  In general, when
you see an error about an expression having the wrong number of parts,
you have parentheses in the wrong place.  Reindenting works based on
the parentheses, and will probably make your error clear.

--Carl

On 2/17/07, Teresa Stanton <tms43 at clearwire.net> wrote:
>
> I'm very new to Scheme and need some help.  I'm trying to write a function
> that accepts an accumulating function(summation, product) and a list of
> numbers and returns the accumulation of the operation on each element of the
> list.  So, if '(1 2 3 4) was supplied to the function and an operation 'sum'
> that adds two elements the function would return the sum of the list.
>
> This is what I have started with and I keep getting an error:
>
> (define (doall fn l)
>   (if (null? (cdr l)
>           (list (fn(car l)))
>           (append (process_all fn(cdr l))(list fn(car l))))))
>
> The error is this:
>
> 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)))))
>
> I am trying to define the list with this function.  I suppose after I can
> get it to work, next I will work on the summation, product function.  First
> I need to get this list function to work.  Any ideas?
>
> Trista


Posted on the users mailing list.