scala/scala — pull request #2788 by ScrapCodes (2013-07-31 11:26:24+00:00)
Title: An attempt at making scala repl's class generation customizable

We at spark, have to customize scala repl to support our way of "code wrapping" for input code. The reason we want it that way is spark needs code serializable so that it can be executed on a remote worker.

I wish it was possible to configure rather than change scala repl code for every scala release migration. This pull request may *only* present my intentions which is, we may not need a complete overhauling of scala REPL to support it and thus there should be a simpler solution to it. It also has a sample customization which uses `class` instead of `object` for wrapping code to be executed. The sample customization is exactly what we would need for spark i.e. serializable. Actually there is more space for making things in the repl customizable, but then this is just a beginning. This has been done in this particular way only to achieve the goal in minimal code change at expense of elegance. Of course suggestions and reviews comments are welcomed for me being on lurker side trying to step into space that might not be welcoming for its technical depth.

For Example

```scala
val a = 10 // show
```
is wrapped as

```scala
class $read extends Serializable {
def () = {
super.;
()
};
def $line = " val a = 10 // show\n";
def $trees = Nil;
class $iwC extends Serializable {
def () = {
super.;
()
};
class $iwC extends Serializable {
def () = {
super.;
()
};
val a = 10
};
val $iw = new $iwC.
};
val $iw = new $iwC.
}
object $read extends scala.AnyRef {
def () = {
super.;
()
};
val INSTANCE = new $read.
}
a: Int = 10

```