Guest User

Untitled

a guest
Feb 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;; Y combinator
  4. (define (simple-Y h)
  5. ((lambda (x) (x x))
  6. (lambda (g)
  7. (h (lambda args (apply (g g) args))))))
  8.  
  9. ;; recursive Y combinator
  10. (define (rec-Y h)
  11. (lambda args (apply (h (rec-Y h)) args)))
  12.  
  13. ;; fibonacci
  14. (define fib
  15. (rec-Y (lambda (self)
  16. (lambda (x)
  17. (if (< x 2)
  18. x
  19. (+ (self (- x 1)) (self (- x 2))))))))
  20.  
  21. (displayln (for/list ((i 10)) (fib i)))
Add Comment
Please, Sign In to add comment