(define from-to ; TYPE: (-> (number number) ; (-> ((-> (number) void)) ; void)) (lambda (from to) (lambda (step) ; EFFECT: if from <= to, then ; do (step from), (step (add1 from)) , ..., (step to) in that order, ; otherwise do nothing (letrec ((loop ; TYPE: (-> (number) void) (lambda (i) ; EFFECT: do (step i), (step (add1 i)), ..., (step to) (if (<= i to) (begin (step i) (loop (add1 i))))))) (loop from))))) (define from-to-iterate ; TYPE: (-> (number number) ; (-> ((-> (number S) S)) ; (-> (S) S))) (lambda (from to) (lambda (next-acc) (lambda (init-acc) ; ENSURES: if from < to, then ; result is (next-acc to ... ; (next-acc (add1 from) (next-acc from init-acc))) ; otherwise result is init-acc (letrec ((loop ; TYPE: (-> (number S) S) (lambda (i acc) ; REQUIRES: from <= i <= to and acc is ; (next-acc (sub1 i) ... ; (next-acc (add1 from) (next-acc from init-acc))) (if (> i to) acc (loop (add1 i) (next-acc i acc)))))) (loop from init-acc))))))