[plt-scheme] Adding a list

From: Marco Morazan (morazanm at gmail.com)
Date: Tue Feb 20 12:38:35 EST 2007

Perhaps, it would help for you to think about what each function expects as
input and what the expected result of each function is. If you are familair
with grammars, it may also help to define the grammar for a list and
carefully structure your program to correspond to the different types of
list that may exist.

I realize these are very high-level descriptions of my suggestions, but my I
hope is that they will provoke some throughts that will lead to a clear
design and implementation. It would help very little if anyone simply gave
you the answer.

I hope it helps,

Marco

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
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070220/4ae75fe2/attachment.html>

Posted on the users mailing list.