fork download
  1. #!/usr/bin/racket
  2. #lang racket
  3.  
  4. (define (inc x) (+ x 1))
  5. (define (square x) (* x x))
  6.  
  7. ; Composition of one-argument functions f and g
  8. ; (f, g) -> f(g(x))
  9. (define (compose f g)
  10. (lambda (x) (f (g x))))
  11.  
  12. (define (repeated func times)
  13. (if (= times 1)
  14. func
  15. (compose func (repeated func (- times 1)))))
  16.  
  17. (display ((repeated inc 5) 5))
  18. (newline)
  19.  
  20. (display ((repeated square 2) 5))
  21. (newline)
  22.  
  23.  
  24. ((repeated inc 5) 0)
  25.  
  26. ((lambda (x)
  27. (lambda (x) (compose inc (repeated inc 4)))) 0)
  28.  
  29. ((lambda (x)
  30. (lambda (x) (compose inc
  31. (lambda (x) (compose inc (repeated inc 3))))) 0)
  32.  
  33.  
  34.  
Runtime error #stdin #stdout #stderr 0.02s 8656KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: In procedure primitive-load:
ERROR: In procedure skip_block_comment: /home/h10StQ/prog.scm:34:1: unterminated `#! ... !#' comment