Created
October 31, 2014 04:08
-
-
Save Centaur/418076edce1357f95e81 to your computer and use it in GitHub Desktop.
dynamically run scala code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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