summaryrefslogtreecommitdiff
path: root/src/dotnet-library
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-11-18 02:03:26 +0000
committermichelou <michelou@epfl.ch>2007-11-18 02:03:26 +0000
commite1f5fa089bb1d1196f4c2fc4ec3780da2865f6f9 (patch)
tree1656c58ebf1dc7885b299e73098232dcbfc27f4b /src/dotnet-library
parent78940081aba843f7ed5299564046130d2806efc1 (diff)
downloadscala-e1f5fa089bb1d1196f4c2fc4ec3780da2865f6f9.tar.gz
scala-e1f5fa089bb1d1196f4c2fc4ec3780da2865f6f9.tar.bz2
scala-e1f5fa089bb1d1196f4c2fc4ec3780da2865f6f9.zip
fixed #176 (CLDC build)
Diffstat (limited to 'src/dotnet-library')
-rw-r--r--src/dotnet-library/scala/List.scala42
1 files changed, 30 insertions, 12 deletions
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 <code>n</code> first elements of this list, or else the whole
* list, if it has less than <code>n</code> 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 <code>n</code> 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 <code>n</code> 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
}
+