From htang at hpl.hp.com  Sat Nov 15 00:00:18 2003
From: htang at hpl.hp.com (htang@hpl.hp.com)
Date: Fri Nov 14 23:59:16 2003
Subject: [Rd] documentation of "scope": possible error + cleanup (PR#5095)
Message-ID: <20031114230018.9CC5EEFB6@slim.kubism.ku.dk>

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.


[Rd] documentation of "scope": possible error + cleanup (PR#5095)
htang@hpl.hp.com