Last active
September 20, 2018 10:43
-
-
Save jiamo/79b6cfa7c4796392ad96a02abbaa408e to your computer and use it in GitHub Desktop.
Ycombinator1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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