an ornithological study of functional birds
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
442B

  1. # y-combinator.. i don't even
  2. warumvogel <- function (f) {
  3. selfinvoke <- function (x) x(x)
  4. almostdrossel <- function (m) function (...) f(m(m), ...)
  5. selfinvoke(almostdrossel)
  6. }
  7. # more compact
  8. warumvogel <- function (f) {
  9. (function (x) x(x))(
  10. function (m) function (...) f(m(m), ...)
  11. )
  12. }
  13. # todo: even more compact using S & K combinators?
  14. fac <- warumvogel(function(self, n) {
  15. if (n < 2) 1
  16. else n * self(n - 1)
  17. })
  18. fac(8)