Anonymous recursion: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 466: | Line 466: | ||
>>> [ Y(fib)(i) for i in range(-2, 10) ] |
>>> [ Y(fib)(i) for i in range(-2, 10) ] |
||
[None, None, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]</lang> |
[None, None, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]</lang> |
||
=={{header|R}}== |
|||
R provides Recall() as a wrapper which finds the calling function, with limitations; Recall will not work if passed to another function as an argument. |
|||
<lang R>fib2 <- function(n) { |
|||
(n >= 0) || stop("bad argument") |
|||
( function(n) if (n <= 1) 1 else Recall(n-1)+Recall(n-2) )(n) |
|||
}</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |