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.
17 lines
371 B
R
17 lines
371 B
R
# Drossel: fn => fn(fn)
|
|
# usage: drossel(function(self, arg1, arg2))
|
|
# it's basically just a factory hiding the function name
|
|
# in a closure. easy!
|
|
drossel <- function (func) function (...) func(func, ...)
|
|
|
|
# example: factorial
|
|
# TODO: play with lazy evaluation?
|
|
fac_ <- function (self, n) {
|
|
if (n < 2) 1
|
|
else n * self(self, n - 1)
|
|
}
|
|
|
|
fac <- drossel(fac_)
|
|
|
|
fac(8)
|