You cannot 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
442 B
R

# y-combinator.. i don't even
warumvogel <- function (f) {
selfinvoke <- function (x) x(x)
almostdrossel <- function (m) function (...) f(m(m), ...)
selfinvoke(almostdrossel)
}
# more compact
warumvogel <- function (f) {
(function (x) x(x))(
function (m) function (...) f(m(m), ...)
)
}
# todo: even more compact using S & K combinators?
fac <- warumvogel(function(self, n) {
if (n < 2) 1
else n * self(n - 1)
})
fac(8)