[Nice-commit] Nice/stdlib/nice/lang array.nice,1.37,1.38
Brought to you by:
bonniot
|
From: Daniel B. <bo...@us...> - 2005-03-07 14:21:35
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12317/stdlib/nice/lang Modified Files: array.nice Log Message: Added fill method for bidimensional arrays. Index: array.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/array.nice,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** array.nice 29 Jul 2004 12:36:12 -0000 1.37 --- array.nice 7 Mar 2005 14:21:21 -0000 1.38 *************** *** 137,141 **** It is important that no reference to the array is kept, because that would make it possible to store null values in it. ! There is no danger as long as the array is created inside the call, like in the above example. */ --- 137,141 ---- It is important that no reference to the array is kept, because that would make it possible to store null values in it. ! There is no danger as long as the array is created inside the call, like in the above example. */ *************** *** 146,150 **** for (int i = 0; i < array.length; i++) array[i] = value(i); ! return cast(array); } --- 146,179 ---- for (int i = 0; i < array.length; i++) array[i] = value(i); ! return cast(array); // all values have been initialized, the cast is safe ! } ! ! /** ! Fills a newly created bidimensional array with non-null values. ! ! A typical usage is to allocate a new array and set its values at the same time: ! <code> ! String[][] coords = new String[10][10].fill((int i, int j) => ""i","j); ! </code> ! ! The equivalent code in Java would be: ! <code> ! String[][] coords = new String[10][10]; ! for (int i = 0; i < 10; i++) ! for (int j = 0; j < 10; i++) ! coords[i] = i + "," + j; ! </code> ! ! It is important that no reference to the array is kept, ! because that would make it possible to store null values in it. ! There is no danger as long as the array is created inside the call, ! like in the above example. ! */ ! <T, U | U <: T> U[][] fill(T[][] array, (int,int)->U value) ! { ! for (int i = 0; i < array.length; i++) ! for (int j = 0; j < array[i].length; j++) ! array[i][j] = value(i,j); ! return cast(array); // all values have been initialized, the cast is safe } |