Scala uses underscores to create an anonymous function with the smallest expression that is not an identification function.
So, the compiler first tries:
(0 to 20).foreach(print(x => math.pow(2, x => x)))
No, that is an identical function, so it leaves one set of parentheses and tries:
(0 to 20).foreach(print(x => math.pow(2, x)))
This is a nontrivial anonymous function, so it stops there.
source
share