Details
Description
Here is a patch for an overload of the len() builtin, to make it easier to loop over multidimensional arrays:
len(a as array, dimension as int)
Maps onto a.GetLength(dimension)
Sample code:
foo = matrix(int, (2, 3, 4))
print len(foo) //24 total items
print len(foo,0) //2 - length of 1st dimension
print len(foo,1) //3
print len(foo,2) //4
//Passing a value for a non-existent dimension gives error at run-time:
print len(foo,3) //IndexOutOfRangeException
Using it with non-arrays will generate error at compile time:
s = "a string"
print len(s,1) //No overload that takes 2 parameters
patch applied. thanks!