Simple string interpolation.

This allows "%(...)" inside a string literal to interpolate the
stringified result of an expression.

It doesn't support custom interpolators or format strings, but we can
consider extending that later.
This commit is contained in:
Bob Nystrom
2015-11-11 07:55:48 -08:00
parent 71575d9179
commit 78655c68b0
41 changed files with 321 additions and 129 deletions
+6 -7
View File
@@ -26,8 +26,8 @@ var stretchDepth = maxDepth + 1
var start = System.clock
System.print("stretch tree of depth " + stretchDepth.toString + " check: " +
Tree.new(0, stretchDepth).check.toString)
System.print("stretch tree of depth %(stretchDepth) check: " +
"%(Tree.new(0, stretchDepth).check)")
for (i in 1...1000) System.gc()
var longLivedTree = Tree.new(0, maxDepth)
@@ -45,16 +45,15 @@ while (depth < stretchDepth) {
check = check + Tree.new(i, depth).check + Tree.new(-i, depth).check
}
System.print((iterations * 2).toString + " trees of depth " +
depth.toString + " check: " + check.toString)
System.print("%(iterations * 2) trees of depth %(depth) check: %(check)")
for (i in 1...1000) System.gc()
iterations = iterations / 4
depth = depth + 2
}
System.print("long lived tree of depth " + maxDepth.toString + " check: " +
longLivedTree.check.toString)
System.print(
"long lived tree of depth %(maxDepth) check: %(longLivedTree.check)")
for (i in 1...1000) System.gc()
System.print("elapsed: " + (System.clock - start).toString)
System.print("elapsed: %(System.clock - start)")