[plt-scheme] How to change the following code to make it handle nested lists?

From: Marco Morazan (morazanm at gmail.com)
Date: Tue Nov 25 08:46:28 EST 2008

On Mon, Nov 24, 2008 at 1:50 AM, SamuelXiao <foolsmart2005 at gmail.com> wrote:
> I have following code:
>
> (define (mysum list)
>   (if (null? list)
>       0
>      (+ (car list) (mysum (cdr list)))
>    )
> )
>

So, by looking at the above code the parameter, list, is a
list-of-numbers defined as:

1. empty OR
2. (cons n L), where n is a number and L is a list-of-numbers.

> to handle case like '(1 (2 3) 4), how can I make it?

'(1 (2 3) 4) is *NOT* a list-of-numbers. Define this type of data as
list-of-numbers above and it should become clear how to solve your
problem.

-- 

Cheers,

Marco


Posted on the users mailing list.