Skip to content

Instantly share code, notes, and snippets.

@jiamo
Last active September 20, 2018 10:43
Show Gist options
  • Save jiamo/79b6cfa7c4796392ad96a02abbaa408e to your computer and use it in GitHub Desktop.
Save jiamo/79b6cfa7c4796392ad96a02abbaa408e to your computer and use it in GitHub Desktop.
Ycombinator1
#lang racket
(define (factorial n)
(if (= n 0)
1
(* n (factorial (- n 1)))))
(define factorial_lambda
(lambda (n)
(if (= n 0)
1
(* n (factorial_lambda (- n 1))))))
(define almost-factorial
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n ((f f) (- n 1))))))) ;; the (f f) is so important to understand
(define sort-of-factorial
(lambda (n)
(if (= n 0)
1
(* n ((almost-factorial almost-factorial) (- n 1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment