Nice/stdlib/nice/lang array.nice,1.37,1.38

Daniel Bonniot <[email protected]>
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
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
  }
  



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.