Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created October 31, 2014 04:08
Show Gist options
  • Save Centaur/418076edce1357f95e81 to your computer and use it in GitHub Desktop.
Save Centaur/418076edce1357f95e81 to your computer and use it in GitHub Desktop.
dynamically run scala code
import tools.nsc.interpreter.IMain
import tools.nsc.Settings
object CommaSeperatedData extends App {
val data = """ "Doe, John", 35, 225, "5'10\"", "555-0123" """
val settings = new Settings
settings.usejavacp.value = true
val n = new IMain(settings)
n.interpret("List(" + data + ")")
n.namedDefinedTerms.foreach(println)
// n.visibleTermNames.foreach(println)
assert(n.valueOfTerm("res0") == Some(List("Doe, John", 35, 225, "5'10\"", "555-0123")))
n.interpret("val x = 1")
n.namedDefinedTerms.foreach(println)
// n.visibleTermNames.foreach(println)
assert(n.valueOfTerm("x") == Some(1))
n.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment