;;; ;;; Part IV ;;; (define x 0) (define (f) (set! x (+ x 1)) x ) (define (repeatl f k) (if (<= k 0) '() ;; make sure (f) gets called before making tail of list. (let ((x (f))) (cons x (repeatl f (- k 1))) ) ) ) (define (repeatr f k) (reverse (repeatl f k)) ) ;; Tail-recursive implementation of same (define (my-repeatl f k) (define (my-repeatl-helper f k collect) (if (<= k 0) collect (let ((x (f))) (my-repeatl-helper f (- k 1) (cons x collect))))) (my-repeatl-helper f k '()) ) (define (my-repeatr f k) (reverse (my-repeatl f k)))