fork(2) 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. ((repeated inc 5) 0)
  26.  
  27. ((lambda (x)
  28. (lambda (x) (compose inc (repeated inc 4)))) 0)
  29.  
  30. ((lambda (x)
  31. (compose inc
  32. (lambda (x) (compose inc (repeated inc 3))))) 0)
  33.  
Success #stdin #stdout 0.03s 8656KB
stdin
Standard input is empty
stdout
10
625