an ornithological study of functional birds
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

17 行
371B

  1. # Drossel: fn => fn(fn)
  2. # usage: drossel(function(self, arg1, arg2))
  3. # it's basically just a factory hiding the function name
  4. # in a closure. easy!
  5. drossel <- function (func) function (...) func(func, ...)
  6. # example: factorial
  7. # TODO: play with lazy evaluation?
  8. fac_ <- function (self, n) {
  9. if (n < 2) 1
  10. else n * self(self, n - 1)
  11. }
  12. fac <- drossel(fac_)
  13. fac(8)