exercise-1.43-repeated-function-application-function.rkt 638 B

123456789101112131415161718192021222324
  1. #lang racket
  2. (define (Mb-to-B n) (* n 1024 1024))
  3. (define MAX-BYTES (Mb-to-B 64))
  4. (custodian-limit-memory (current-custodian) MAX-BYTES)
  5. (define (square x)
  6. (* x x))
  7. (define (compose f g)
  8. (lambda (x)
  9. (f (g x))))
  10. (define (repeated func repeated-application-count)
  11. (define (iter result-function remaining-applications-count)
  12. (display "remaining-applications-count: ") (display remaining-applications-count) (newline)
  13. (if
  14. (= remaining-applications-count 1)
  15. result-function
  16. (iter
  17. (compose func result-function)
  18. (- remaining-applications-count 1))))
  19. (iter func repeated-application-count))
  20. ((repeated square 2) 5)