I am trying to get my head around as to why having a local variable or a for loop inside a function is not considered to be pure functional programming.
Given this function:
int as_int(char *str)
{
int acc; /* accumulate the partial result */
for (acc = 0; isdigit(*str); str++) {
acc = acc * 10 + (*str - '0');
}
return acc;
}
Under what circumstances would the variable acc be a side-effect ? Even in a concurrent environment each invocation of the function would have its own copy of acc. So I don't quite get why it isn't allowed in functional programming.
Aucun commentaire:
Enregistrer un commentaire