(let loop ((lst l) (len 0))
(cond
((empty? lst) len)
(else
(loop
(rest lst)
(+ len 1))))))
When length is called, it begins the loop. The first iteration, lst
is bound to the argument of length and len
is bound to zero. Then, if lst
is not empty, the loop repeats, with len
bound to a number one larger than the last iteration and lst
bound to the rest of the list. Finally, when lst
is empty, the accumulated length is returned.