[plt-scheme] Re: Some fine distinctions

From: wooks (wookiz at hotmail.com)
Date: Wed May 13 12:58:05 EDT 2009


On May 13, 2:47 pm, Robby Findler <ro... at eecs.northwestern.edu> wrote:
> (but it is an arity error so maybe that doesn't count...)
>
Ach!!

fixed the arity error and the incorrect base case.

sumlists :: listoflists -> number
(define sumlists
   (lambda (a-list)
      (let sumlists ([a-list a-list] [accum 0])
        (cond
         [(empty? a-list) accum]
         [(list? (first a-list)) (sumlists (rest a-list)
                                  (+ accum (sumlists (first a-list))
0))]
         [else (sumlists (rest a-list) (+ accum (first a-list)))]))))

So I repeat. It's not tail recursive and I don't see how it could be
made to be.
If I'm right about the first two, isn't one better off writing it
stack recursively.





Posted on the users mailing list.