[svn] r6111: nemerle/trunk/lib: list.n tests/Makefile

nazgul svnadmin at nemerle.org
Mon Feb 6 21:10:55 CET 2006


Log:
Add methods for copying list to array

Author: nazgul
Date: Mon Feb  6 21:10:52 2006
New Revision: 6111

Modified:
   nemerle/trunk/lib/list.n
   nemerle/trunk/lib/tests/Makefile

Modified: nemerle/trunk/lib/list.n
==============================================================================
--- nemerle/trunk/lib/list.n	(original)
+++ nemerle/trunk/lib/list.n	Mon Feb  6 21:10:52 2006
@@ -443,15 +443,36 @@
     public ToArray () : array ['a]
     {
       def result = array (Length);
+      CopyTo (result);
+      result
+    }
       
+    /**
+     * Copies first [len] elements from current list to specified array beginning with index 0
+     */
+    public CopyTo (dest : array ['a], len : int) : void
+    {
       mutable i = 0;
       foreach (el in this) {
-        result [i] = el;
+        when (i >= len) Nemerle.Imperative.Break ();
+        dest [i] = el;
         i++;
       }
-      result
+      when (i < len)
+        throw System.ArgumentException ($"insufficient amount of elements in current list: expected $len, has $i");
     }
     
+    /**
+     * Copies all elements from current list to specified array beginning with index 0
+     */
+    public CopyTo (dest : array ['a]) : void
+    {
+      mutable i = 0;
+      foreach (el in this) {
+        dest [i] = el;
+        i++;
+      }
+    }
 
     public MapToArray ['b] (f : 'a -> 'b) : array ['b]
     {

Modified: nemerle/trunk/lib/tests/Makefile
==============================================================================
--- nemerle/trunk/lib/tests/Makefile	(original)
+++ nemerle/trunk/lib/tests/Makefile	Mon Feb  6 21:10:52 2006
@@ -4,6 +4,7 @@
 
 EXECUTE = $(NET_ENGINE) $(NET_FLAGS)
 THISDIR = $(shell if cygpath --help 2>/dev/null 1>&2; then echo `cygpath -m $(CURDIR)`; else echo $(CURDIR); fi)
+UNIT_SCR = linkedlist.n list.n
 
 ############################################################
 # TARGETS
@@ -24,5 +25,5 @@
 
 lib-unit-tests.dll: 
 	$(Q)if test $(NUNIT_CONSOLE); then \
-		$(EXECUTE) $(TOP)/ncc/out.stage3/ncc.exe linkedlist.n -def:NUNIT $(NUNIT_LIB) -t:library -o:lib-unit-tests.dll; \
+		$(EXECUTE) $(TOP)/ncc/out.stage3/ncc.exe $(UNIT_SRC) -def:NUNIT $(NUNIT_LIB) -t:library -o:lib-unit-tests.dll; \
 	fi



More information about the svn mailing list