Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Created May 24, 2011 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethTisue/989801 to your computer and use it in GitHub Desktop.
Save SethTisue/989801 to your computer and use it in GitHub Desktop.
for BASE talk
import scala.util.DynamicVariable
class Workspace {
def run(s: String) { println(s) }
def report(s: String) = 10
def dispose() { println("disposed") }
}
def expect[T](expected: T)(actual: T) {
assert(expected == actual, actual.toString)
}
val workspace =
new DynamicVariable[Workspace](null)
val run = workspace.value.run(_)
val report = workspace.value.report(_)
def testLanguage(name: String)
(body: => Unit) {
val w = new Workspace
try workspace.withValue(w) { body }
finally w.dispose()
}
testLanguage("create and count") {
run("create-turtles 10")
expect(10)(
report("count turtles"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment