Capturing the Enclosing Environment
scala> val n = 3 n: Int = 3 scala> val fun = (x:Int) => n *x fun: (Int) => Int = <function> scala> fun(2) res0: Int = 6 scala> def mulBy(n : Int) =(x:Int) => n * x mulBy: (Int)(Int) => Int scala> val quadruple = mulBy(4) quadruple: (Int) => Int = <function> scala> quadruple(5) res1: Int = 20