![]() ![]() ![]() | An iterative list-length function - continuation passing style - handling improper lists. | Lecture 3 - slide 33 : 43 Program 7 |
(define (list-length-iter-cps lst res k0) (cond ((null? lst) (k0 res)) ((pair? lst) (list-length-iter-cps (cdr lst) (+ res 1) k0)) (else (k0 'improper-list)))) ; k0 is passed along the tail recursive calls, and ; can also be used for passing 'an exceptional value'.