Logo

Programming-Idioms

  • C++

Idiom #264 Automated passing of array bounds

Pass a two-dimensional integer array a to a procedure foo and print the size of the array in each dimension. Do not pass the bounds manually. Call the procedure with a two-dimensional array.

def foo(a):
    print(len(a), len(a[0]))
    return


a = [[1,2,3], [4,5,6]]
foo(a)
foo = lambda a: \
    print(*(len(x) for x in a))
foo(a)
def foo(a):
    print(*(len(x) for x in a))
foo(a)
foo(List<List<int>> a) => print("${a.length} ${a[0].length}");
var a = [
    [1, 2],
    [3, 4],
    [5, 6]
  ];
foo(a);

New implementation...
< >
tkoenig