Is Odersky serious with "bills !*&^%~ code!"?
obfuscation, puzzle, scala, syntax
Solution
What Odersky means to say is that it would be possible to have valid code looking like that. For instance, the code below:
class BadCode(whose: String, source: String) {
def ! = println(whose+", what the hell do you mean by '"+source+"'???")
}
class Programmer(who: String) {
def !*&^%~(source: String) = new BadCode(who, source)
}
val bills = new Programmer("Bill")
val code = "def !*&^%~(source: String) = new BadCode(who, source)"
bills !*&^%~ code!
Just copy&paste it on the REPL.
Problem
In his book programming in scala (Chapter 5 Section 5.9 Pg 93) Odersky mentioned this expression "`bills !*&^%~ code!`" In the footnote on same page: "By now you should be able to figure out that given this code,the Scala compiler would invoke `(bills.!*&^%~(code)).!()."` That's a bit to cryptic for me, could someone explain what's going on here?