htang@hpl.hp.com
2003-Nov-14 23:59 UTC
[Rd] documentation of "scope": possible error + cleanup (PR#5095)
Full_Name: Hsiu-Khuern Tang Version: 1.8.0 OS: Debian GNU/Linux unstable Submission from: (NULL) (156.153.255.243) While reading the R lang info pages, I came across the following paragraphs in the node "Scope":>> A simple example, >> >> f <- function(x) { >> y <- 10 >> g <- function(x) x + y >> return(g) >> } >> h <- f() >> h(3) >> >> A rather interesting question is what happens when `h' is evaluated . >> To describe this we need a bit more notation. Within a function body >> variables can be bound, local or unbound. The bound variables are those >> that match the formal arguments to the function. The local variables are >> those that were created or defined within the function body. The unbound >> variables are those that are neither local or bound . When a function >> body is evaluated there is no problem determining values for local >> variables or for bound variables. Scoping rules determine how the >> language will find values for the unbound variables. >> >> When `h(3)' is evaluated we see that its body is that of `g'. >> Within that body `x' and `y' are unbound. In a language with lexical >> scope `x' will be associated with the value 3 and `y' with the value 1 >> 0 >> so `h()' should return the value 13. In R this is indeed what happens >> .Possible error: it says in the last paragraph that `x' and `y' are unbound. Shouldn't it be that `x' is bound, since it is a formal argument of `h', and `y' is unbound? Also, in the previous paragraph, the portion "To describe this we need a bit more notation ... neither local or [sic] bound" should be removed, since the explanation of bound, local, and unbound variables had just been given a few paragraphs earlier. Best, Hsiu-Khuern.
Reasonably Related Threads
- plot.rpart ignores uniform=TRUE if graphics device is not open (PR#7361)
- cannot assign to NULL dimnames (PR#1042)
- Wishlist: user-specified color names for palette() (PR#4836)
- typos in src/main/gram.y (PR#8780)
- Notes on building a gcc toolchain for Rtools (but not multilib)