Schema Count number of element in the list

77 views Asked by At

I know we have a function to count number of items in a list, however in this procedure I am can not use this function. So how can I count number of elements in a list.

(define (last_element l count )
      (+ count 2)
      (if (null? cdr l)
          done  
      (last_element (cdr l) count)))

(last_element (list 1 2 3 4 5) 0)
1

There are 1 answers

0
Anup Singh On
(define (mylength2 l count)
 (if (null? l) count
     (mylength2 (cdr l) (+ count 1))))