4 ms·
My main beef with R is that this is valid code: > f <- function (n) { + f <- 1 + if (n == 0) return(f) else n * f(n-1)} > f(5) [1]
by discardable_dan 8y ago
My main beef with R is that this is valid code:
> f <- function (n) {
+ f <- 1
+ if (n == 0) return(f) else n * f(n-1)}
> f(5)
[1] 120
The language has some warts, that's for sure.
- hatmatrix 8y agoIsn't that just lisp-2-like behavior where functions and data maintain separate identities?
- kgwgk 8y agoNo, if you set f <- 42 between the moment where you define f as a function and the moment where you call it then it doesn't work anymore: > f(5) Error in f(5) : could not find function "f"
- Tarq0n 8y agoFunctions having their own environment is actually pretty useful once you get your head around them.