From the book of "Functional programming in scala", I see the definition of "referential transparent" of an expression:

> 
> An expression e is referentially transparent if, for all programs p, all occurrences of e in p can be replaced by the result of evaluating e without affecting the meaning of p.
> 
> 
> 

I have some code examples that I'm not sure if they are referentially transparent or not. 

I will use `scala.collection.mutable.StringBuilder` in the examples which is a mutable class

**1.**

```
val x = new StringBuilder("Hello")

println(x.length)
println(x.length)

```

Suppose the code here is the whole and complete code that uses `x`.

Can I say expression `x` is a referential transparent expression? 

If I change all `x` with its value `new StringBuilder("Hello")`, the observable behavior of the program is not changed:

```
val x = new StringBuilder("Hello")

println(new StringBuilder("Hello").length)
println(new StringBuilder("Hello").length)

```

**2.**

```
val x = new StringBuilder("Hello")
val y = x.append("aaa")

```

Suppose the code here is the whole and complete code that uses `x` and `y`.

Can I say `y` is referential transparent because it's not used at all in the program?

**3.**

```
def getTheClassName(n:Int):String = {
  val x = new StringBuilder("hello")
  for(int i=0;i<n;i++) {
    x.append("world")
  }
  return x.getClass.getName
}

```

Can I say the `x` is referential transparent? Because no matter how I replace it with its value, the return value will not changed.

PS: Maybe the main problem is that I don't understand what does `for all programs p` mean, does it mean the existing complete code? Or any possible code that may be added?