I noticed that just after posting.

I changed to:
(define (length2 lst)
  (define (l-iter l count)
    (if (null? l) count
        (l-iter (cdr l) (+ count 1))))
  (l-iter lst 0))

Must get better at spotting obvious mistakes...


On 20 November 2013 11:27, Pierpaolo Bernardi <[email protected]> wrote:

> On Wed, Nov 20, 2013 at 12:09 PM, Bo Gus <[email protected]> wrote:
> > My tail recursive implementation of length is like this:
> >
> > (define (length2 l)
> >   (define (l-iter l count)
> >     (if (null? 1) count
> >         (l-iter (cdr l) (+ count 1))))
> >   (l-iter l 0))
>
> > I am fairly new to scheme.  What am I doing wrong?
>
> You wrote (null? 1), which is always false.  Note 1 instead of l.
>
> Cheers
>
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to