# [plt-scheme] Some fine distinctions

 From: Robby Findler (robby at eecs.northwestern.edu) Date: Wed May 13 09:47:10 EDT 2009 Previous message: [plt-scheme] Some fine distinctions Next message: [plt-scheme] Re: Some fine distinctions Messages sorted by: [date] [thread] [subject] [author]

```(but it is an arity error so maybe that doesn't count...)

Robby

On Wed, May 13, 2009 at 8:46 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> (+ accum (sumlists (first a-list)))
>
> On Wed, May 13, 2009 at 8:44 AM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> Which one is not?
>>
>> On May 13, 2009, at 8:40 AM, Robby Findler wrote:
>>
>>> Actually not every call to sumlists is in tail position.
>>>
>>> Robby
>>>
>>> On Wednesday, May 13, 2009, Matthias Felleisen <matthias at ccs.neu.edu>
>>> wrote:
>>>>
>>>> On May 13, 2009, at 7:24 AM, wooks wrote:
>>>>
>>>>
>>>> Didn't fully absorb that. So
>>>>
>>>>
>>>> sumlists :: listoflists -> number
>>>> (define sumlists
>>>>   (lambda (a-list)
>>>>      (let sumlists ([a-list a-list] [accum 0])
>>>>        (cond
>>>>         [(empty? a-list) 0]
>>>>         [(list? (first a-list)) (sumlists (rest a-list)
>>>>                                  (+ accum (sumlists (first a-list)))]
>>>>         [else (sumlists (rest a-list) (+ accum (first a-list)))]))))
>>>>
>>>> This is accumulative and I used to think ergo tail recursive.
>>>> If I am right and it is not (because of the evaluation of the list?
>>>> case)...is there any way to write this sort of function tail
>>>> recursively. It looks to me not... at least not in this style of
>>>> programming.
>>>>
>>>>
>>>> Every call to the (inner) sumlist is in tail position, ergo this function
>>>> is tail-recursive.
>>>>
>>>> ;; ---
>>>>
>>>> The accumulator statement is
>>>>
>>>>  ;; accum is the sum of all numbers between a-list0 and a-list
>>>>
>>>> (Of course, you failed to name your parameters properly so go back to the
>>>> original reply and check it out.)
>>>>
>>>> ;; ---
>>>>
>>>> What I am saying is that accumulator-style does NOT imply tail-recursion.
>>>>
>>>> _________________________________________________