Both R
and C
have lexical scope. So assuming that global scope is empty, in C
the following code would not work :
int aux(int arg) {
if (arg > 0) {
int result = 1;
} else {
int result = 0;
}
return result;
}
While in R
the following code :
aux <- function(arg) {
if (arg > 0) {
result = 1
} else {
result = 0
}
return(result)
}
Works properly. Can someone tell me what is the difference in scoping between R
and C
which makes these two functions behave differently?