fork download
  1.  
  2. ;#!/usr/bin/racket
  3. ;#lang racket
  4.  
  5. (define (inc x) (+ x 1))
  6. (define (square x) (* x x))
  7.  
  8. ; Composition of one-argument functions f and g
  9. ; (f, g) -> f(g(x))
  10. (define (compose f g)
  11. (lambda (x) (f (g x))))
  12.  
  13. (define (repeated func times)
  14. (if (= times 1)
  15. func
  16. (compose func (repeated func (- times 1)))))
  17.  
  18. (display ((repeated inc 5) 5))
  19. (newline)
  20.  
  21. (display ((repeated square 2) 5))
  22. (newline)
  23.  
  24.  
  25. (display ((repeated inc 5) 0))
  26.  
  27. (display ((compose inc (repeated inc 4)) 0))
  28.  
  29. (display ((compose inc (compose inc (repeated inc 3))) 0))
  30.  
Success #stdin #stdout 0.05s 8616KB
stdin
Standard input is empty
stdout
10
625
555