Logo

Programming-Idioms

  • JS
  • Dart

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.

foo(List<List<int>> a) => print("${a.length} ${a[0].length}");
var a = [
    [1, 2],
    [3, 4],
    [5, 6]
  ];
foo(a);
module x
contains
  subroutine foo(a)
    integer, dimension(:,:) :: a
    print *,size(a,1), size(a,2)
  end subroutine foo
end module x

program main
  use x
  integer, dimension(5,10) :: a
  call foo(a)
end program main

New implementation...
< >
tkoenig