Posts

Showing posts from September, 2013

Macros in Scala: moderately complex example

Image
I recently began to discover the power of newly-added macros in Scala. While they are still labeled as "experimental" , they already pack quite a punch. Most tutorials on the web usually use some simple examples - like assert macro , or debugging helper . In this post, I'll try to make a bit deeper dive into the subject, in hope that I will be able to explore darker corners of macro engineering. The use-case for today's macro is actually something I needed in one of my real projects - I had complex hierarchy of case classes, and I wanted a quick way to visualize it (without needing to read mile-long text files). So I created a macro, that takes case class, and creates a frame with JTree containing the hierarchy of case class members. Example use-case for the macro looks as follows: case class Author(name: String, birthYear: Int) case class Book(title: String, authors: List[Author]) val hobbit = Book("Hobbit: There And Back Again", List(Author(...

/dev/null for graphics

Have the following ever happened to you? You are trying to automate some data processing step. The step in question involves some complex, GUI-driven application, for which there is no source available or that source is a little to complex do dive in and extract the required functionality. As a happy coincidence, the application includes batch mode - but it still creates and displays the gui when running in batch mode (even when started with "nogui" option). (in my particular situation, the app in question was Brainstorm , a collection of Matlab scripts. The original author is using Windows exclusively, thus he probably couldn't even imagine this scenario) All of the above could be acceptable, but there is a slight problem - batch processing happens on a mainframe-style Linux server, without keyboard, display, or even X server running. Thus the application starts up, tries to create it's cosy GUI, obviously fails, and crashes hard. When applications...