Created
December 5, 2017 08:24
-
-
Save lagenorhynque/71adba2eece784e5f553797e251b3cba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| user=> (def fact | |
| #_=> ((fn [f] | |
| #_=> ((fn [x] (x x)) | |
| #_=> (fn [y] (f (fn [& args] (apply (y y) args)))))) | |
| #_=> (fn [f] | |
| #_=> (fn [n] (if (< n 2) 1 (* n (f (dec n)))))))) | |
| #'user/fact | |
| user=> (for [n (range 10)] (fact n)) | |
| (1 1 2 6 24 120 720 5040 40320 362880) |
This file contains hidden or 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
| >>> fact = (lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args))))(lambda f: lambda n: (1 if n<2 else n*f(n-1))) | |
| >>> [fact(n) for n in range(10)] | |
| [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cf. https://rosettacode.org/wiki/Y_combinator