This program f expr expr -- apply function f to arguments expr, expr -- is equivalent to this one, which factors out `expr` let x = expr -- introduce a new variable `x` with the value of `expr` in f x x
The reason it isn't equivalent comes from the different sorts of expressions that we could find in e. For example, what if e is println("hi!"). If we make that substitution, our snippet looks like the following: f(println("hi"), println("hi")) // isn't really equivalent to! val x = println("hi") f(x, x) Clearly these are not the same two programs. The first prints "hi" twice, while the second only prints it once. This is a violation of referential transparency, and it's why we sometimes say that Scala is an impure language. Any expression which is not referentially transparent must contain side-effects, by definition.
Collection
[
|
...
]