diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-02 13:21:17 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-02 13:21:17 +0000 |
commit | 2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b (patch) | |
tree | 99ccc3aa4c0edacfb907df35e61b0b47f3c331cf /src/dotnet-library | |
parent | 4603e36f932a18eb17a41aecc6b9e74c7655ff0f (diff) | |
download | scala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.tar.gz scala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.tar.bz2 scala-2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b.zip |
Synced src/dotnet-library with rev 17621 of src...
Synced src/dotnet-library with rev 17621 of src/library
Diffstat (limited to 'src/dotnet-library')
-rw-r--r-- | src/dotnet-library/scala/Application.scala | 38 | ||||
-rw-r--r-- | src/dotnet-library/scala/Console.scala | 18 | ||||
-rw-r--r-- | src/dotnet-library/scala/List.scala | 171 | ||||
-rw-r--r-- | src/dotnet-library/scala/Math.scala | 3 | ||||
-rw-r--r-- | src/dotnet-library/scala/Predef.scala | 10 | ||||
-rw-r--r-- | src/dotnet-library/scala/StringBuilder.scala | 21 | ||||
-rw-r--r-- | src/dotnet-library/scala/reflect/Manifest.scala | 28 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/NonLocalReturnException.scala | 2 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichChar.scala | 22 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichString.scala | 18 | ||||
-rw-r--r-- | src/dotnet-library/scala/xml/Attribute.scala | 1 | ||||
-rw-r--r-- | src/dotnet-library/scalax/collection/immutable/List.scala | 20 |
12 files changed, 251 insertions, 101 deletions
diff --git a/src/dotnet-library/scala/Application.scala b/src/dotnet-library/scala/Application.scala index 4867b2eb99..3d94db28ec 100644 --- a/src/dotnet-library/scala/Application.scala +++ b/src/dotnet-library/scala/Application.scala @@ -15,8 +15,9 @@ package scala //import scala.compat.Platform.currentTime /** <p> - * The <code>Application</code> class can be used to quickly turn objects - * into executable programs. Here is an example: + * The <code>Application</code> trait can be used to quickly turn objects + * into executable programs, but is <em>not recommended</em>. + * Here is an example: * </p><pre> * object Main with Application { * Console.println("Hello World!"); @@ -36,6 +37,37 @@ package scala * </p><pre> * java -Dscala.time Main * </pre> + * <p> + * In practice the <code>Application</code> trait has a number of serious + * pitfalls: + * </p> + * <ul> + * <li> Threaded code that references the object will block until static + * initialization is complete. However, because the entire execution of an + * <code>object</code> extending <code>Application</code> takes place during + * static initialization, concurrent code will <em>always</em> deadlock if + * it must synchronize with the enclosing object.</li> + * <li>As described above, there is no way to obtain the + * command-line arguments because all code in body of an <code>object</code> + * extending <code>Application</code> is run as part of the static initialization + * which occurs before <code>Application</code>'s <code>main</code> method + * even begins execution.</li> + * <li>Static initializers are run only once during program execution, and + * JVM authors usually assume their execution to be relatively short. + * Therefore, certain JVM configurations may become confused, or simply fail to + * optimize or JIT the code in the body of an <code>object</code> extending + * <code>Application</code>. This can lead to a significant + * performance degradation.</li> + * </ul> + * + * Instead, it is recommended to define a <code>main</code> method explicitly: + * <pre> + * <b>object</b> Main { + * <b>def</b> main(args: Array[String]) { + * //.. + * } + * } + * </pre> * * @author Matthias Zenger * @version 1.0, 10/09/2003 @@ -51,7 +83,7 @@ trait Application { * * @param args the arguments passed to the main method */ - def main(args: Array[String]) = { + def main(args: Array[String]) { // if (getProperty("scala.time") ne null) { // val total = currentTime - executionStart // Console.println("[total " + total + "ms]") diff --git a/src/dotnet-library/scala/Console.scala b/src/dotnet-library/scala/Console.scala index 5763742ed0..3df51dcd20 100644 --- a/src/dotnet-library/scala/Console.scala +++ b/src/dotnet-library/scala/Console.scala @@ -83,7 +83,7 @@ object Console { * * @param reader specifies the new input stream. */ - def setIn(reader: TextReader): Unit = { + def setIn(reader: TextReader) { inVar.value = reader } @@ -101,8 +101,9 @@ object Console { * * @param obj the object to print. */ - def print(obj: Any): Unit = + def print(obj: Any) { out.Write(if (null == obj) "null" else obj.toString()) + } /** Flush the output stream. This function is required when partial * output (i.e. output not terminated by a new line character) has @@ -112,13 +113,13 @@ object Console { /** Print a new line character on the terminal. */ - def println(): Unit = out.WriteLine() + def println() { out.WriteLine() } /** Print out an object followed by a new line character. * * @param x the object to print. */ - def println(x: Any): Unit = out.WriteLine(x) + def println(x: Any) { out.WriteLine(x) } /** <p> * Prints its arguments as a formatted string, based on a string @@ -140,9 +141,10 @@ object Console { * @see <a href="#printf(java.lang.String,scala.Any*)" * target="contentFrame">Console.printf</a>. */ - def format(text: String, args: Any*): Unit = + def format(text: String, args: Any*) { if (text eq null) out.Write("null") else out.Write(text, args.toArray) + } /** Read a full line from the terminal. Throws System.IO.EndOfStreamException if the end of the * input stream has been reached. @@ -151,8 +153,8 @@ object Console { * @throws System.IO.EndOfStreamException */ def readLine(): String = { - val s = in.ReadLine() - if (s == null) throw new System.IO.EndOfStreamException("Console has reached end of input") else s + val s = in.ReadLine() + if (s == null) throw new System.IO.EndOfStreamException("Console has reached end of input") else s } /** Print a formatted text and read a full line from the terminal. @@ -163,7 +165,7 @@ object Console { * @return the string read from the terminal. */ def readLine(text: String, args: Any*): String = { - format(text, args: _*) + printf(text, args: _*) readLine() } diff --git a/src/dotnet-library/scala/List.scala b/src/dotnet-library/scala/List.scala index 8bda87211f..4aef6126cd 100644 --- a/src/dotnet-library/scala/List.scala +++ b/src/dotnet-library/scala/List.scala @@ -11,7 +11,8 @@ package scala -import scala.collection.mutable.ListBuffer +import scala.collection.mutable.{ListBuffer, LinkedHashMap} +import annotation.tailrec import Predef._ /** This object provides methods for creating specialized lists, and for @@ -54,6 +55,8 @@ object List { * @return the sorted list of all integers in range [start;end). */ def range(start: Int, end: Int, step: Int): List[Int] = { + if (step == 0) + throw new IllegalArgumentException("step is zero") val b = new ListBuffer[Int] var i = start while ((step <= 0 || i < end) && (step >= 0 || i > end)) { @@ -71,7 +74,9 @@ object List { * * @param start the start value of the list * @param end the end value of the list - * @param step the increment function of the list, must be monotonically increasing or decreasing + * @param step the increment function of the list, which given <code>v<sub>n</sub></code>, + * computes <code>v<sub>n+1</sub></code>. Must be monotonically increasing + * or decreasing. * @return the sorted list of all integers in range [start;end). */ def range(start: Int, end: Int, step: Int => Int): List[Int] = { @@ -81,7 +86,10 @@ object List { var i = start while ((!up || i < end) && (!down || i > end)) { b += i - i += step(i) + val next = step(i) + if (i == next) + throw new IllegalArgumentException("the step function did not make any progress on "+ i) + i = next } b.toList } @@ -442,7 +450,7 @@ object List { * @author Martin Odersky and others * @version 1.0, 16/07/2003 */ -sealed abstract class List[+A] extends Seq[A] { +sealed abstract class List[+A] extends Seq[A] with Product { /** Returns true if the list does not contain any elements. * @return <code>true</code>, iff the list is empty. @@ -456,7 +464,16 @@ sealed abstract class List[+A] extends Seq[A] { */ def head: A - /** returns length - l, without calling length + /** Result of comparing <code>length</code> with operand <code>l</code>. + * returns <code>x</code> where + * <code>x < 0</code> iff <code>this.length < l</code> + * <code>x == 0</code> iff <code>this.length == l</code> + * <code>x > 0</code> iff <code>this.length > that</code>. + * + * This method is used by matching streams against right-ignoring (...,_*) patterns. + * + * This method does not call <code>List.length</code>, it works for <code>O(l)</code>, + * not for <code>O(length)</code>. */ override def lengthCompare(l: Int) = { if (isEmpty) 0 - l @@ -523,17 +540,13 @@ sealed abstract class List[+A] extends Seq[A] { /** Appends two list objects. */ - override def ++[B >: A](that: Iterable[B]): List[B] = { - val buf = new ListBuffer[B] - this copyToBuffer buf - that copyToBuffer buf - buf.toList - } + override def ++[B >: A](that: Iterable[B]): List[B] = + this ::: that.toList /** Reverse the given prefix and append the current list to that. * This function is equivalent to an application of <code>reverse</code> * on the prefix followed by a call to <code>:::</code>, but more - * efficient (and tail recursive). + * efficient. * * @param prefix the prefix to reverse and then prepend * @return the concatenation of the reversed prefix and the current list. @@ -690,6 +703,7 @@ sealed abstract class List[+A] extends Seq[A] { * @return the suffix of length <code>n</code> of the list */ def takeRight(n: Int): List[A] = { + @tailrec def loop(lead: List[A], lag: List[A]): List[A] = lead match { case Nil => lag case _ :: tail => loop(tail, lag.tail) @@ -700,7 +714,7 @@ sealed abstract class List[+A] extends Seq[A] { /** Returns the list wihout its rightmost <code>n</code> elements. * * @param n the number of elements to take - * @return the suffix of length <code>n</code> of the list + * @return the list without its rightmost <code>n</code> elements */ def dropRight(n: Int): List[A] = { def loop(lead: List[A], lag: List[A]): List[A] = lead match { @@ -753,9 +767,14 @@ sealed abstract class List[+A] extends Seq[A] { * @return the longest suffix of the list whose first element * does not satisfy the predicate <code>p</code>. */ - override def dropWhile(p: A => Boolean): List[A] = - if (isEmpty || !p(head)) this - else tail dropWhile p + override def dropWhile(p: A => Boolean): List[A] = { + @tailrec + def loop(xs: List[A]): List[A] = + if (xs.isEmpty || !p(xs.head)) xs + else loop(xs.tail) + + loop(this) + } /** Returns the longest prefix of the list whose elements all satisfy * the given predicate, and the rest of the list. @@ -811,6 +830,7 @@ sealed abstract class List[+A] extends Seq[A] { * @return the reversed list of results. */ def reverseMap[B](f: A => B): List[B] = { + @tailrec def loop(l: List[A], res: List[B]): List[B] = l match { case Nil => res case head :: tail => loop(tail, f(head) :: res) @@ -1153,7 +1173,7 @@ sealed abstract class List[+A] extends Seq[A] { var these = this var those = that while (!these.isEmpty && !those.isEmpty) { - b += (these.head, those.head) + b += ((these.head, those.head)) these = these.tail those = those.tail } @@ -1172,7 +1192,7 @@ sealed abstract class List[+A] extends Seq[A] { var idx = 0 while(!these.isEmpty) { - b += (these.head, idx) + b += ((these.head, idx)) these = these.tail idx += 1 } @@ -1204,48 +1224,95 @@ sealed abstract class List[+A] extends Seq[A] { var these = this var those = that while (!these.isEmpty && !those.isEmpty) { - b += (these.head, those.head) + b += ((these.head, those.head)) these = these.tail those = those.tail } while (!these.isEmpty) { - b += (these.head, thatElem) + b += ((these.head, thatElem)) these = these.tail } while (!those.isEmpty) { - b += (thisElem, those.head) + b += ((thisElem, those.head)) those = those.tail } b.toList } - /** Computes the union of this list and the given list - * <code>that</code>. + /** <p> + * Computes the multiset union of this list and the given list + * <code>that</code>. For example: + * </p><pre> + * <b>val</b> xs = List(1, 1, 2) + * <b>val</b> ys = List(1, 2, 2, 3) + * println(xs union ys) // prints "List(1, 1, 2, 1, 2, 2, 3)" + * println(ys union xs) // prints "List(1, 2, 2, 3, 1, 1, 2)" + * </pre> * * @param that the list of elements to add to the list. - * @return a list without doubles containing the elements of this + * @return a list containing the elements of this * list and those of the given list <code>that</code>. */ - def union[B >: A](that: List[B]): List[B] = { - val b = new ListBuffer[B] - var these = this - while (!these.isEmpty) { - if (!that.contains(these.head)) b += these.head - these = these.tail + def union[B >: A](that: List[B]): List[B] = this ++ that + + /** <p> + * Computes the multiset intersection between this list and the + * given list <code>that</code>; the intersection contains <i>m</i> + * copies of an element contained in both lists, where <i>m</i> is + * the smaller of the number of times the element appears in this + * list or in <code>that</code>. For example: + * </p><pre> + * <b>val</b> xs = List(1, 1, 2) + * <b>val</b> ys = List(3, 2, 2, 1) + * println(xs intersect ys) // prints "List(1, 2)" + * println(ys intersect xs) // prints "List(2, 1)" + * </pre> + * + * @param that the list to intersect. + * @return the list of elements contained both in this list and + * in the given list <code>that</code>. + */ + def intersect[B >: A](that: List[B]): List[B] = { + val occ = new LinkedHashMap[B, Int] + that foreach (e => if (occ contains e) occ(e) += 1 else occ(e) = 1) + val buf = new ListBuffer[B] + for (e <- this if occ contains e) { + if (occ(e) > 0) { occ(e) -= 1; buf += e } } - b.prependToList(that) + buf.toList } - /** Computes the difference between this list and the given list - * <code>that</code>. + /** <p> + * Computes the multiset difference between this list and the + * given list <code>that</code>. If an element appears more + * than once in both lists, the difference contains <i>m</i> copies + * of that element, where <i>m</i> is the difference between the + * number of times the element appears in this list and the number + * of times it appears in <code>that</code>. For example: + * </p><pre> + * <b>val</b> xs = List(1, 1, 2) + * <b>val</b> ys = List(1, 2, 2, 3) + * println(xs diff ys) // prints "List(1)" + * println(xs -- ys) // prints "List()" + * </pre> * * @param that the list of elements to remove from this list. - * @return this list without the elements of the given list - * <code>that</code>. - * @deprecated use <code>--</code> instead + * @return the list of elements contained only in this list plus + * <i>m</i> copies of each element present in both lists, + * where <i>m</i> is defined as above. */ - @deprecated - def diff[B >: A](that: List[B]): List[B] = this -- that + def diff[B >: A](that: List[B]): List[B] = { + val occ = new LinkedHashMap[B, Int] + that foreach (e => if (occ contains e) occ(e) += 1 else occ(e) = 1) + val buf = new ListBuffer[B] + for (e <- this) { + if (occ contains e) + if (occ(e) > 0) occ(e) -= 1 + else buf += e + else buf += e + } + buf.toList + } /** Computes the difference between this list and the given list * <code>that</code>. @@ -1271,13 +1338,26 @@ sealed abstract class List[+A] extends Seq[A] { * @return this list without the elements of the given object * <code>x</code>. */ - def - [B >: A](x: B): List[B] = - this -- List(x) + def - [B >: A](x: B): List[B] = { + val b = new ListBuffer[B] + var these = this + while (!these.isEmpty) { + if (these.head != x) b += these.head + these = these.tail + } + b.toList + } /** Concatenate the elements of this list. The elements of this list * should be a <code>Iterables</code>. * - * Note: The compiler might not be able to infer the type parameter. + * Note: The compiler might not be able to infer the type parameter, + * so it is recommended to provide an explicit type argument. + * + * Example: + * <code>List(List(1, 3), List(2)).flatten[Int]</code> + * returns + * <code>List(1, 3, 2)</code> * * @param f An implicit conversion to an <code>Iterable</code> instance. * @return The concatenation of all elements of iterables in this list. @@ -1288,15 +1368,6 @@ sealed abstract class List[+A] extends Seq[A] { buf.toList } - /** Computes the intersection between this list and the given list - * <code>that</code>. - * - * @param that the list to intersect. - * @return the list of elements contained both in this list and - * in the given list <code>that</code>. - */ - def intersect[B >: A](that: List[B]): List[B] = filter(x => that contains x) - /** Removes redundant elements from the list. Uses the method <code>==</code> * to decide if two elements are identical. * diff --git a/src/dotnet-library/scala/Math.scala b/src/dotnet-library/scala/Math.scala index 2315a064ec..89829135c0 100644 --- a/src/dotnet-library/scala/Math.scala +++ b/src/dotnet-library/scala/Math.scala @@ -134,7 +134,7 @@ object Math { // from Java 1.5 // def log10(x: Double): Double = java.lang.Math.log10(x) // def cbrt(x: Double): Double = java.lang.Math.cbrt(x) - + // // def ulp(x: Double): Double = java.lang.Math.ulp(x) // def ulp(x: Float): Float = java.lang.Math.ulp(x) // def sinh(x: Double): Double = java.lang.Math.sinh(x) @@ -143,5 +143,4 @@ object Math { // def hypot(x: Double, y: Double): Double = java.lang.Math.hypot(x, y) // def expm1(x: Double): Double = java.lang.Math.expm1(x) // def log1p(x: Double): Double = java.lang.Math.log1p(x) - } diff --git a/src/dotnet-library/scala/Predef.scala b/src/dotnet-library/scala/Predef.scala index 5ddd535f58..da2255e3a9 100644 --- a/src/dotnet-library/scala/Predef.scala +++ b/src/dotnet-library/scala/Predef.scala @@ -60,7 +60,7 @@ object Predef { type Function[-A, +B] = Function1[A, B] - type Map[A, B] = collection.immutable.Map[A, B] + type Map[A, +B] = collection.immutable.Map[A, B] type Set[A] = collection.immutable.Set[A] val Map = collection.immutable.Map @@ -82,7 +82,7 @@ object Predef { throw new Error("assertion failed") } - def assert(assertion: Boolean, message: Any) { + def assert(assertion: Boolean, message: => Any) { if (!assertion) throw new Error("assertion failed: " + message) } @@ -92,7 +92,7 @@ object Predef { throw new IllegalArgumentException("assumption failed") } - def assume(assumption: Boolean, message: Any) { + def assume(assumption: Boolean, message: => Any) { if (!assumption) throw new System.Security.SecurityException("assumption failed: "+ message) } @@ -102,7 +102,7 @@ object Predef { throw new IllegalArgumentException("requirement failed") } - def require(requirement: Boolean, message: Any) { + def require(requirement: Boolean, message: => Any) { if (!requirement) throw new IllegalArgumentException("requirement failed: "+ message) } @@ -131,6 +131,7 @@ object Predef { class ArrowAssoc[A](x: A) { def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y) + def →[B](y: B): Tuple2[A, B] = ->(y) } implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x) @@ -180,6 +181,7 @@ object Predef { implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x) implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) + implicit def unitWrapper(x: Boolean) = new runtime.RichUnit implicit def stringWrapper(x: String) = new runtime.RichString(x) //implicit def stringBuilderWrapper(x : StringBuilder): runtime.RichStringBuilder = new runtime.RichStringBuilder(x) diff --git a/src/dotnet-library/scala/StringBuilder.scala b/src/dotnet-library/scala/StringBuilder.scala index 31fc360c2d..fc65e6335a 100644 --- a/src/dotnet-library/scala/StringBuilder.scala +++ b/src/dotnet-library/scala/StringBuilder.scala @@ -15,15 +15,15 @@ import Predef._ /** <p> * A mutable sequence of characters. This class provides an API compatible - * with <code>java.lang.StringBuilder</code>, but with no guarantee of - * synchronization. + * with <a class="java/lang/StringBuilder" href="" target="_top"> + * <code>java.lang.StringBuilder</code></a>. * </p> * * @author Stephane Micheloud * @version 1.0 */ final class StringBuilder(initCapacity: Int, private val initValue: String) -extends (Int => Char) with Proxy { + extends (Int => Char) { if (initCapacity < 0) throw new IllegalArgumentException if (initValue eq null) throw new NullPointerException @@ -51,8 +51,6 @@ extends (Int => Char) with Proxy { append(initValue) - def self = this - def toArray: Array[Char] = value def length: Int = count @@ -765,6 +763,7 @@ extends (Int => Char) with Proxy { * @return a reference to this object. */ def reverse(): StringBuilder = { + import StringBuilder._ var hasSurrogate = false val n = count - 1 var j = (n-1) >> 1 @@ -773,8 +772,8 @@ extends (Int => Char) with Proxy { val temp2 = value(n - j) if (!hasSurrogate) hasSurrogate = - (temp >= StringBuilder.MIN_SURROGATE && temp <= StringBuilder.MAX_SURROGATE) || - (temp2 >= StringBuilder.MIN_SURROGATE && temp2 <= StringBuilder.MAX_SURROGATE) + (temp >= MIN_HIGH_SURROGATE && temp <= MAX_LOW_SURROGATE) || + (temp2 >= MIN_HIGH_SURROGATE && temp2 <= MAX_LOW_SURROGATE) value(j) = temp2 value(n - j) = temp j -= 1 @@ -784,9 +783,9 @@ extends (Int => Char) with Proxy { var i = 0 while (i < count - 1) { val c2 = value(i) - if (StringBuilder.isLowSurrogate(c2)) { + if (isLowSurrogate(c2)) { val c1 = value(i + 1) - if (StringBuilder.isHighSurrogate(c1)) { + if (isHighSurrogate(c1)) { value(i) = c1; i += 1 value(i) = c2 } @@ -811,8 +810,8 @@ extends (Int => Char) with Proxy { } -object StringBuilder { - +object StringBuilder +{ private val MIN_HIGH_SURROGATE = '\uD800' private val MAX_HIGH_SURROGATE = '\uDBFF' diff --git a/src/dotnet-library/scala/reflect/Manifest.scala b/src/dotnet-library/scala/reflect/Manifest.scala index 125c1ed73e..0d8bb61e93 100644 --- a/src/dotnet-library/scala/reflect/Manifest.scala +++ b/src/dotnet-library/scala/reflect/Manifest.scala @@ -22,7 +22,7 @@ package scala.reflect * these operators should be on the unerased type. * </p> */ -trait Manifest[T] { +trait Manifest[T] extends OptManifest[T] { /** A class representing the type U to which T would be erased. Note * that there is no subtyping relationship between T and U. */ @@ -59,6 +59,8 @@ trait Manifest[T] { case _ => false } + private[reflect] def typeArguments: Option[List[Manifest[_]]] = None + } /** <p> @@ -97,8 +99,18 @@ object Manifest { def classType[T](clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = new Manifest[T] { val erasure = clazz - val typeArguments: Seq[Manifest[_]] = args - override lazy val toString = erasure.getName + typeArguments.mkString("[", ", ", "]") + private[reflect] override val typeArguments = Some(args.toList) + override def <:<(that: Manifest[_]): Boolean = { + that.typeArguments match { + case Some(thatArgs) => + super.<:<(that) && args.equalsWith(thatArgs) { (x, y) => x <:< y } + case None => + false + } + } + override lazy val toString = + (if (erasure.isArray) "Array" else erasure.getName) + + args.toList.mkString("[", ", ", "]") } /** Manifest for the class type `prefix # clazz'. */ @@ -112,8 +124,9 @@ object Manifest { def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = new Manifest[T] { val erasure = clazz - val typeArguments: Seq[Manifest[_]] = args - override lazy val toString = prefix.toString + "#" + clazz.getName + typeArguments.mkString("[", ", ", "]") + private[reflect] override val typeArguments = Some(args.toList) + override lazy val toString = + prefix.toString + "#" + erasure.getName + typeArguments.mkString("[", ", ", "]") } /** Manifest for the abstract type `prefix # name'. `upperBound' is not @@ -129,8 +142,9 @@ object Manifest { def abstractType[T](prefix: Manifest[_], name: String, upperBound: Manifest[_], args: Manifest[_]*): Manifest[T] = new Manifest[T] { lazy val erasure = upperBound.erasure - val typeArguments: Seq[Manifest[_]] = args - override lazy val toString = prefix.toString + "#" + name + typeArguments.mkString("[", ", ", "]") + private[reflect] override val typeArguments = Some(args.toList) + override lazy val toString = + prefix.toString + "#" + name + typeArguments.mkString("[", ", ", "]") } /** Manifest for the intersection type `parents_0 with ... with parents_n'. */ diff --git a/src/dotnet-library/scala/runtime/NonLocalReturnException.scala b/src/dotnet-library/scala/runtime/NonLocalReturnException.scala index 1ee4db6ac7..09025f7e94 100644 --- a/src/dotnet-library/scala/runtime/NonLocalReturnException.scala +++ b/src/dotnet-library/scala/runtime/NonLocalReturnException.scala @@ -14,4 +14,4 @@ package scala.runtime import Predef.RuntimeException -class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException +class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException
\ No newline at end of file diff --git a/src/dotnet-library/scala/runtime/RichChar.scala b/src/dotnet-library/scala/runtime/RichChar.scala index 75bd80022a..75599e3744 100644 --- a/src/dotnet-library/scala/runtime/RichChar.scala +++ b/src/dotnet-library/scala/runtime/RichChar.scala @@ -51,20 +51,24 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] { def toLowerCase: Char = System.Char.ToLower(x) def toUpperCase: Char = System.Char.ToUpper(x) - /** Create an Iterator[Char] over the characters from 'x' to 'y' - 1 + /** Create a <code>RandomAccessSeq.Projection[Char]</code> over the characters from 'x' to 'y' - 1 */ - def until(limit: Char): Iterator[Char] = new Iterator[Char] { - private var ch = x - def hasNext: Boolean = ch < limit - def next: Char = - if (hasNext) { val j = ch; ch = (ch + 1).toChar; j } - else throw new NoSuchElementException("next on empty iterator") + def until(limit: Char): RandomAccessSeq.Projection[Char] = + if (limit <= x) RandomAccessSeq.empty.projection + else + new RandomAccessSeq.Projection[Char] { + def length = limit - x + def apply(i: Int): Char = { + Predef.require(i >= 0 && i < length) + (x + i).toChar + } + override def stringPrefix = "RandomAccessSeq.Projection" } //def until(y: Char): Iterator[Char] = to(y) - /** Create an Iterator[Char] over the characters from 'x' to 'y' + /** Create a <code>RandomAccessSeq.Projection[Char]</code> over the characters from 'x' to 'y' */ - def to(y: Char): Iterator[Char] = until((y + 1).toChar) + def to(y: Char): RandomAccessSeq.Projection[Char] = until((y + 1).toChar) } diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala index 3342d7ae9f..1151174b00 100644 --- a/src/dotnet-library/scala/runtime/RichString.scala +++ b/src/dotnet-library/scala/runtime/RichString.scala @@ -199,6 +199,24 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char def toArray: Array[Char] = { self.ToCharArray() } + + /** <p> + * Uses the underlying string as a pattern (in a fashion similar to + * printf in C), and uses the supplied arguments to fill in the + * holes. + * </p> + * <p> + * The interpretation of the formatting patterns is described in + * <a href="" target="contentFrame" class="java/util/Formatter"> + * <code>java.util.Formatter</code></a>. + * </p> + * + * @param args the arguments used to instantiating the pattern. + * @throws java.lang.IllegalArgumentException + */ + // def format(args : Any*) : String = + // the toList is necessary right now because Array(1,2,3).toArray[Any] throws a CCE + // Predef.format(self, args.toList.toArray[Any].asInstanceOf[Array[AnyRef]]: _*) } object RichString { diff --git a/src/dotnet-library/scala/xml/Attribute.scala b/src/dotnet-library/scala/xml/Attribute.scala new file mode 100644 index 0000000000..7dc776594e --- /dev/null +++ b/src/dotnet-library/scala/xml/Attribute.scala @@ -0,0 +1 @@ +/* Attribute.scala does not exist for the dotnet target */ diff --git a/src/dotnet-library/scalax/collection/immutable/List.scala b/src/dotnet-library/scalax/collection/immutable/List.scala index c30f3b772f..72af5a0278 100644 --- a/src/dotnet-library/scalax/collection/immutable/List.scala +++ b/src/dotnet-library/scalax/collection/immutable/List.scala @@ -12,7 +12,8 @@ package scalax.collection.immutable import mutable.ListBuffer -import generic.covariant.{SequenceTemplate, SequenceFactory} +import generic.{SequenceTemplate, SequenceFactory, EmptyIterableFactory, Builder} +import annotation.unchecked.uncheckedVariance /** A class representing an ordered collection of elements of type * <code>a</code>. This class comes with two implementing case @@ -23,7 +24,9 @@ import generic.covariant.{SequenceTemplate, SequenceFactory} * @author Martin Odersky and others * @version 2.8 */ -sealed abstract class List[+A] extends Stream[A] with SequenceTemplate[List, A] with Product { +sealed abstract class List[+A] extends Stream[A] + with SequenceTemplate[List, A @uncheckedVariance] + with Product { import collection.{Iterable, OrderedIterable, Sequence, Vector} @@ -549,7 +552,7 @@ final case class ::[B](private var hd: B, private[scalax] var tl: List[B]) exten * @author Martin Odersky and others * @version 1.0, 15/07/2003 */ -object List extends SequenceFactory[List] { +object List extends SequenceFactory[List] with EmptyIterableFactory[List] { override val empty: List[Nothing] = Nil @@ -566,7 +569,9 @@ object List extends SequenceFactory[List] { * @deprecated use @see iterate instead. * @param start the start value of the list * @param end the end value of the list - * @param step the increment function of the list, must be monotonically increasing or decreasing + * @param step the increment function of the list, which given <code>v<sub>n</sub></code>, + * computes <code>v<sub>n+1</sub></code>. Must be monotonically increasing + * or decreasing. * @return the sorted list of all integers in range [start;end). */ @deprecated def range(start: Int, end: Int, step: Int => Int): List[Int] = { @@ -576,7 +581,10 @@ object List extends SequenceFactory[List] { var i = start while ((!up || i < end) && (!down || i > end)) { b += i - i += step(i) + val next = step(i) + if (i == next) + throw new IllegalArgumentException("the step function did not make any progress on "+ i) + i = next } b.toList } @@ -693,7 +701,7 @@ object List extends SequenceFactory[List] { * in the same order * @deprecated use `array.toList` instead */ - def fromArray[A](arr: Array[A]): List[A] = fromArray(arr, 0, arr.length) + @deprecated def fromArray[A](arr: Array[A]): List[A] = fromArray(arr, 0, arr.length) /** Converts a range of an array into a list. * |