Skip to content
Prev 165150 / 398506 Next

understanding recursive functions

joseph.g.boyer at gsk.com wrote on 12/18/2008 04:22 PM:
All references to x save one (the assignment with the <<- operator) are 
found within the current frame, not by lexical scoping, and hence is 
never changed... producing infinite recursion. The following at least 
fixes your example:

All references to x save one (the assignment with the <<- operator) are 
found within the current frame, not by lexical scoping, and hence is 
never changed... producing infinite recursion. The following at least 
fixes your example:

q <- function(x,h) {if (x < 2) {x <<- x+1; x <- x+1; return(q(x))} else 
return(x)}
ls() # no x in global env just yet
q(-10)
ls()


Jeff