Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;; Y combinator
- (define (simple-Y h)
- ((lambda (x) (x x))
- (lambda (g)
- (h (lambda args (apply (g g) args))))))
- ;; recursive Y combinator
- (define (rec-Y h)
- (lambda args (apply (h (rec-Y h)) args)))
- ;; fibonacci
- (define fib
- (rec-Y (lambda (self)
- (lambda (x)
- (if (< x 2)
- x
- (+ (self (- x 1)) (self (- x 2))))))))
- (displayln (for/list ((i 10)) (fib i)))
Add Comment
Please, Sign In to add comment