wolfe-pack / moro

Interactive documentation and programming with Scala, iPython notebook style.
http://wolfe-pack.github.io/moro
BSD 2-Clause "Simplified" License
19 stars 3 forks source link

Reuse results from previous scala snippets #27

Closed riedelcastro closed 10 years ago

riedelcastro commented 10 years ago

For the more complex examples in Wolfe it would be nice to break up scala snippets and interleave them with text. It would be great if I could decide for a given cell whether it starts a new scope, or reuses the one from above. By default we can start new scopes to get the behaviour we currently have.

Several obvious ways come to mind:

riedelcastro commented 10 years ago

Most awesome! Can I control whether there is reuse or not?

sameersingh commented 10 years ago

Yes, see aggregate option in reference.conf.

For a running example, see wolfe/docs/examples/03_grids, the server is up on earth.

riedelcastro commented 10 years ago

This is nice. Another idea to cache compilation is to wrap each snippet cell in a "object" and create an own compilation unit for it. If a cell uses a previous cell, it simply imports that object into scope.

riedelcastro commented 10 years ago

Can I change aggregation on a per-cell basis? That is, I want some cells to start a fresh scope?

sameersingh commented 10 years ago

The problem with combined compiling are the following:

No aggregation is currently at Application level. It's very easy to otherwise set it up on a cell-level, I just don't know what the interface should be for such configurations. A row of config checkboxes over the editor? A collapsible toolbar? Actually, maybe a form that appears if you click a gears icon.

riedelcastro commented 10 years ago

Can't you do

object Cell1 {
   val x = 5
   val y = 10
   def apply() = x + y
}
object Cell2 {
  import Cell1._
  val z = y + x + 5
  def apply() = z
}
riedelcastro commented 10 years ago

As for the interface, if it was only for defining scopes I would just add a single checkbox/toggle "start a new scope". But I assume there may be more of such properties coming, so yeah, a form makes sense.

sameersingh commented 10 years ago

The problem is that I can't assume just the last line is the one returning something, i.e.

Map("key1" -> 10,
    "key2" -> 100)

So given a String snippet of code, I have no direct way of figuring out where to insert def apply =.

riedelcastro commented 10 years ago

Maybe you can use a light-weight scala parser. Not sure if something like the parser from scalariform would work.