From e58673295a780ab7e9e2098a907df3466866a300 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 17 Jun 2009 21:23:05 +0000 Subject: Newly generated Tuple/Product/Function classes ... Newly generated Tuple/Product/Function classes from new genprod, plus a couple minor tweaks to genprod to keep tests happy. --- src/build/genprod.scala | 82 ++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/build') diff --git a/src/build/genprod.scala b/src/build/genprod.scala index f5dd393d3d..ee3f79c292 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -112,32 +112,30 @@ import genprod._ zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz */ object FunctionZero extends Function(0) { - override def descriptiveComment = functionNTemplate.format("currentSeconds", "anonfun0", """ - * - * val currentSeconds = () => System.currentTimeMillis() / 1000L - * - * val anonfun0 = new Function0[Long] { - * def apply(): Long = System.currentTimeMillis() / 1000L - * } - * - * println(currentSeconds()) - * println(anonfun0()) -""") + override def descriptiveComment = functionNTemplate.format("currentSeconds", "anonfun0", +""" * + * val currentSeconds = () => System.currentTimeMillis() / 1000L + * + * val anonfun0 = new Function0[Long] { + * def apply(): Long = System.currentTimeMillis() / 1000L + * } + * + * println(currentSeconds()) + * println(anonfun0())""") override def moreMethods = "" } object FunctionOne extends Function(1) { - override def descriptiveComment = functionNTemplate.format("succ", "anonfun1", """ - * - * val succ = (x: Int) => x + 1 - * - * val anonfun1 = new Function1[Int, Int] { - * def apply(x: Int): Int = x + 1 - * } - * - * println(succ(0)) - * println(anonfun1(0)) -""") + override def descriptiveComment = functionNTemplate.format("succ", "anonfun1", +""" * + * val succ = (x: Int) => x + 1 + * + * val anonfun1 = new Function1[Int, Int] { + * def apply(x: Int): Int = x + 1 + * } + * + * println(succ(0)) + * println(anonfun1(0))""") override def moreMethods = """ /** (f compose g)(x) == f(g(x)) @@ -151,17 +149,16 @@ object FunctionOne extends Function(1) { } object FunctionTwo extends Function(2) { - override def descriptiveComment = functionNTemplate.format("max", "anonfun2", """ - * - * val max = (x: Int, y: Int) => if (x < y) y else x - * - * val anonfun2 = new Function2[Int, Int, Int] { - * def apply(x: Int, y: Int): Int = if (x < y) y else x - * } - * - * println(max(0, 1)) - * println(anonfun2(0, 1)) -""") + override def descriptiveComment = functionNTemplate.format("max", "anonfun2", +""" * + * val max = (x: Int, y: Int) => if (x < y) y else x + * + * val anonfun2 = new Function2[Int, Int, Int] { + * def apply(x: Int, y: Int): Int = if (x < y) y else x + * } + * + * println(max(0, 1)) + * println(anonfun2(0, 1))""") } object Function @@ -178,13 +175,14 @@ object Function class Function(val i: Int) extends Group("Function") with Arity { val functionNTemplate = """

- In the following example the definition of - * %s is a shorthand for the anonymous class - * definition %s: - *

- *
-  *  object Main extends Application { %s
-  *  }
""" + * In the following example the definition of + * %s is a shorthand for the anonymous class + * definition %s: + *

+ *
+ *  object Main extends Application {
+%s
+ *  }
""" def toStr() = "\"" + ("" format i) + "\"" def apply() = { @@ -258,12 +256,12 @@ class Tuple(val i: Int) extends Group("Tuple") with Arity { // prettifies it a little if it's overlong def mkToString() = { - def str(xs: List[String]) = xs.mkString(""" + ", " + """) + def str(xs: List[String]) = xs.mkString(""" + "," + """) if (i <= MAX_ARITY / 2) str(mdefs) else { val s1 = str(mdefs take (i / 2)) val s2 = str(mdefs drop (i / 2)) - s1 + " +\n \", \" + " + s2 + s1 + " +\n \",\" + " + s2 } } -- cgit v1.2.3