diff options
Diffstat (limited to 'sources/scala/Predef.scala')
-rw-r--r-- | sources/scala/Predef.scala | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala index cdd2eee20f..56cd07ed60 100644 --- a/sources/scala/Predef.scala +++ b/sources/scala/Predef.scala @@ -1,61 +1,62 @@ -package scala { +package scala; - module Predef { +module Predef { - val True = Boolean.True; - val False = Boolean.False; + val True = Boolean.True; + val False = Boolean.False; - val List = scala.List; + val List = scala.List; - def List[a](x: a*): List[a] = { - def mkList(elems: Iterator[a]): List[a] = - if (elems.hasNext) elems.next :: mkList(elems) - else Nil(); - mkList(x.elements); - } - - def error[err](x: String):err = new java.lang.RuntimeException(x).throw; + def List[a](x: a*): List[a] = { + def mkList(elems: Iterator[a]): List[a] = + if (elems.hasNext) elems.next :: mkList(elems) + else Nil(); + mkList(x.elements); + } - def try[a](def block: a): Except[a] = - new Except(scala.runtime.ResultOrException.tryBlock(block)); + def error[err](x: String):err = new java.lang.RuntimeException(x).throw; - def range(lo: Int, hi: Int): List[Int] = - if (lo > hi) List() else lo :: range(lo + 1, hi); + def try[a](def block: a): Except[a] = + new Except(scala.runtime.ResultOrException.tryBlock(block)); - def while(def condition: Boolean)(def command: Unit): Unit = - if (condition) { - command; while(condition)(command) - } else { - } + def range(lo: Int, hi: Int): List[Int] = + if (lo > hi) List() else lo :: range(lo + 1, hi); - trait Until { - def until(def condition: Boolean): Unit + def while(def condition: Boolean)(def command: Unit): Unit = + if (condition) { + command; while(condition)(command) + } else { } - def repeat(def command: Unit): Until = - new Until { - def until(def condition: Boolean): Unit = { - command ; - if (condition) {} - else until(condition) - } + trait Until { + def until(def condition: Boolean): Unit + } + + def repeat(def command: Unit): Until = + new Until { + def until(def condition: Boolean): Unit = { + command ; + if (condition) {} + else until(condition) } + } - type Pair = Tuple2; - def Pair[a, b](x: a, y: b) = Tuple2(x, y); + type Pair = Tuple2; + def Pair[a, b](x: a, y: b) = Tuple2(x, y); - type Triple = Tuple3; - def Triple[a, b, c](x: a, y: b, z: c) = Tuple3(x, y, z); - } + type Triple = Tuple3; + def Triple[a, b, c](x: a, y: b, z: c) = Tuple3(x, y, z); +} - class Except[a](r: scala.runtime.ResultOrException[a]) { - def except(handler: PartialFunction[Throwable, a]): a = - if (r.exc == null) r.result - else if (handler isDefinedAt r.exc) handler(r.exc) - else r.exc.throw; - def finally(def handler: Unit): a = - if (r.exc == null) r.result else { handler; r.exc.throw } - } +class Except[a](r: scala.runtime.ResultOrException[a]) { + def except(handler: PartialFunction[Throwable, a]): a = + if (r.exc == null) r.result as a + else if (handler isDefinedAt r.exc) handler(r.exc) + else r.exc.throw; + def finally(def handler: Unit): a = + if (r.exc == null) r.result as a else { handler; r.exc.throw } } + + |