Created
May 24, 2011 21:41
-
-
Save SethTisue/989801 to your computer and use it in GitHub Desktop.
for BASE talk
This file contains 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 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