Scala 2.10 has experimental support for macros which alike sophisticated compile-time code generation. See here for more detail.
There are some fun examples on Jason Zaugg's macrocosm git repository, and the SLICK library which is an evolution of the ScalaQuery SQL DSL enabling type-safe database (and collection) queries to be expressed in a LINQ-like way.
And this example, from the expecty assertion library:
import org.expecty.Expecty
case class Person(name: String = "Fred", age: Int = 42) {
def say(words: String*) = words.mkString(" ")
}
val person = Person()
val expect = new Expecty()
...
val word1 = "ping"
val word2 = "pong"
expect {
person.say(word1, word2) == "pong pong"
}
Yielding:
java.lang.AssertionError:
person.say(word1, word2) == "pong pong"
| | | | |
| | ping pong false
| ping pong
Person(Fred,42)