From e1f5fa089bb1d1196f4c2fc4ec3780da2865f6f9 Mon Sep 17 00:00:00 2001 From: michelou Date: Sun, 18 Nov 2007 02:03:26 +0000 Subject: fixed #176 (CLDC build) --- src/dotnet-library/scala/List.scala | 42 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/dotnet-library') diff --git a/src/dotnet-library/scala/List.scala b/src/dotnet-library/scala/List.scala index e50d8e9bc5..4f5693dc4f 100644 --- a/src/dotnet-library/scala/List.scala +++ b/src/dotnet-library/scala/List.scala @@ -401,7 +401,6 @@ sealed abstract class List[+A] extends Seq[A] { */ def head: A - /** returns length - l, without calling length */ override def lengthCompare(l: Int) = { @@ -457,9 +456,14 @@ sealed abstract class List[+A] extends Seq[A] { * @param prefix the prefix to reverse and then prepend * @return the concatenation of the reversed prefix and the current list. */ - def reverse_:::[B >: A](prefix: List[B]): List[B] = prefix match { - case Nil => this - case head :: tail => (head :: this).reverse_:::(tail) + def reverse_:::[B >: A](prefix: List[B]): List[B] = { + var these: List[B] = this + var pres = prefix + while (!pres.isEmpty) { + these = pres.head :: these + pres = pres.tail + } + these } /** Returns the number of elements in the list. @@ -541,8 +545,15 @@ sealed abstract class List[+A] extends Seq[A] { */ override def last: A = if (isEmpty) throw new Predef.NoSuchElementException("Nil.last") - else if (tail.isEmpty) head - else tail.last + else { + var cur = this + var next = this.tail + while (!next.isEmpty) { + cur = next + next = next.tail + } + cur.head + } /** Returns the n first elements of this list, or else the whole * list, if it has less than n elements. @@ -581,9 +592,15 @@ sealed abstract class List[+A] extends Seq[A] { * @param n the number of elements to drop. * @return the list without its n first elements. */ - override def drop(n: Int): List[A] = - if (isEmpty || n <= 0) this - else (tail drop (n-1)) + override def drop(n: Int): List[A] = { + var these = this + var count = n + while (!these.isEmpty && count > 0) { + these = these.tail + count -= 1 + } + these + } /** Returns the rightmost n elements from this list. * @@ -1219,8 +1236,9 @@ case object Nil extends List[Nothing] { * @version 1.0, 15/07/2003 */ @SerialVersionUID(0L - 8476791151983527571L) -final case class ::[B](hd: B, private[scala] var tl: List[B]) extends List[B] { - def head = hd - def tail = tl +final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extends List[B] { + def head : B = hd + def tail : List[B] = tl override def isEmpty: Boolean = false } + -- cgit v1.2.3