Boo
  1. Boo
  2. BOO-298

len overload for multidimensional arrays

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.5
    • Fix Version/s: 0.7
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      1

      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

        Activity

        Hide
        Rodrigo B. de Oliveira added a comment -

        patch applied. thanks!

        Show
        Rodrigo B. de Oliveira added a comment - patch applied. thanks!

          People

          • Assignee:
            Rodrigo B. de Oliveira
            Reporter:
            Doug H
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: