Hi all,
A reminder that the very able Ken Scambler will be presenting on Scala
2.10's upcoming macro feature at our next Scala meeting, next Monday
May 28th at our regular venue VLSCI. Arrive from 6pm, talks start at
6:30. Hope you can make it.
Macro's essentially make the compiler extendible by the application,
tool or library programmer, in a much more accessible, safe, and
reusable fashion than the older compiler plugins did.
On this topic, last night I watched the ScalaDays talk on macros, by
their creator Eugene Burmako, assisted by EPFL colleague Christopher
Vogt [
http://skillsmatter.com/podcast/scala/kepler-metaprogramming-scala].
He is one very smart guy and his talk really brought home to me how
much power macros bring to the table. Even given that Scala is
littered with powerful tools, this one is a biggie. As well as noting
that already macros are already being used inside the scala compiler
codebase to simplify and reduce it, he talks about the upcoming SLICK
tool, Scala's version of LINQ. Although at face-value macros allow
application-code to execute at compile- rather than run- time, in
SLICK they are fruitfully applied to do the reverse: compile time code
is lifted via a macro into an LINQ-like "expression tree", to be
manipulated at runtime. This is the secret sauce that allows scala
code to transform into SQL queries that are sent to the database for
execution.
Macros seem to offer a much more elegant way to integrate datastore
queries into the language than the approach employed by earlier
frameworks such as Squeryl. For example, looking at this squeryl
code....
class Artist(val id: Long, val name:String) {
def songs = from(MusicDb.songs)(s => where(s.artistId === id) select(s))
}
...you might wonder
(a) Why is the where condition a function of some strange parameter 's'?
(b) Why is equality tested with '===' ?
And in seeking the answers, you'll discover that Squeryl is keeping a
straight face while inwardly going through painful contortions in
order to defer the execution of any code in the query, since it wants
to turn it all into SQL.
It was a valiant attempt, given the available technology, but macros
offer a much more elegant way to "write-as-scala", but "run-as-X",
where X might be SQL, Javascript, or GPU code.
-Ben