diff options
author | Paul Phillips <paulp@improving.org> | 2009-12-02 04:59:54 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-12-02 04:59:54 +0000 |
commit | a030f0d8b3f19c88c857adbeea7e8712fb6a8c8e (patch) | |
tree | f7984d43a1e87ea1b093900bbeb3f34b2380bcd6 /src/build/genprod.scala | |
parent | 87fa83d3f91bd151eaacdb98862af66021fd5b38 (diff) | |
download | scala-a030f0d8b3f19c88c857adbeea7e8712fb6a8c8e.tar.gz scala-a030f0d8b3f19c88c857adbeea7e8712fb6a8c8e.tar.bz2 scala-a030f0d8b3f19c88c857adbeea7e8712fb6a8c8e.zip |
Built out genprod to create a tuple method for ...
Built out genprod to create a tuple method for reach function alongside
its curry method. Generated new FunctionNs.
Diffstat (limited to 'src/build/genprod.scala')
-rw-r--r-- | src/build/genprod.scala | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/build/genprod.scala b/src/build/genprod.scala index 8abbe2d77b..c14ed8c40a 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -200,9 +200,12 @@ trait {className}{contraCoArgs} extends AnyRef {{ self => }} </file> } + + private def commaXs = xdefs.mkString("(", ", ", ")") + // (x1: T1) => (x2: T2) => (x3: T3) => (x4: T4) => apply(x1,x2,x3,x4) def shortCurry = { - val body = xdefs.mkString("apply(", ",", ")") + val body = "apply" + commaXs List.map2(xdefs, targs)("(%s: %s) => ".format(_, _)).mkString("", "", body) } @@ -210,24 +213,36 @@ trait {className}{contraCoArgs} extends AnyRef {{ self => def longCurry = (List.map2(xdefs, targs)(_ + ": " + _) drop 1).mkString( "(x1: T1) => ((", ", ", - ") => self.apply(%s)).curry".format(xdefs mkString ",") + ") => self.apply%s).curry".format(commaXs) ) // f(x1,x2,x3,x4,x5,x6) == (f.curry)(x1)(x2)(x3)(x4)(x5)(x6) def curryComment = { """ - /** f(%s) == (f.curry)%s + /** f%s == (f.curry)%s */ -""".format(xdefs mkString ",", xdefs map ("(" + _ + ")") mkString) +""".format(commaXs, xdefs map ("(" + _ + ")") mkString) + } + + def tupleMethod = { + def comment = """ + /* f%s == (f.tuple)(Tuple%d%s) + */ +""".format(commaXs, i, commaXs) + def body = "case Tuple%d%s => apply%s".format(i, commaXs, commaXs) + + comment + " def tuple: Tuple%d%s => R = {\n %s\n }\n".format(i, invariantArgs, body) } def curryMethod = { val body = if (i < 5) shortCurry else longCurry + + curryComment + " def curry: %s => R = {\n %s\n }\n".format( targs mkString " => ", body ) } - override def moreMethods = curryComment + curryMethod + override def moreMethods = curryMethod + tupleMethod } // object Function |