Scoping assignment and local, bound and global variable in R

I am new to R and trying to figure out behavior of local,bound and global variables. I am confused with the following problem. If I write the function in the following way, then what are the local, bound and global variables of function f?

f <- function(a ="") {
  return_a <- function() a
  set_a <- function(x)
      a <<- x
  list(return_a,set_a)
}


ANSWERS:


return_a is a function. set_a is a function. They are both functional objects (with associated environments, but using the word "variable" to describe them seems prone to confusion. If you call f, you get a list of twofunctions. When you create a list, there are not necessarily names to the list so p$set_a("Carl") throws an error because there is no p[['set_a']].

> p <- f("Justin"); p$set_a("Carl")
Error: attempt to apply non-function

But p[[2]] now returns a function and you need to call it:

>  p[[2]]
function(x)
      a <<- x
<environment: 0x3664f6a28>

> p[[2]]("Carl")

That did change the value of the symbol-a in the environment of p[[1]]:

> p[[1]]()
[1] "Carl"


 MORE:


 ? javascript variable global and local scope confusion
 ? javascript variable global and local scope confusion
 ? javascript variable global and local scope confusion
 ? Why is this function wrapped in parentheses, followed by parentheses?
 ? Why is this function wrapped in parentheses, followed by parentheses?
 ? Why is this function wrapped in parentheses, followed by parentheses?
 ? Why is the function with in parenthesis?
 ? I'd like to understand the jQuery plugin syntax
 ? Deathmatch: Self Executing Anonymous Function -vs- "new function"
 ? How to allow multiple instances in javascript if object wrapped in anonymous func