## Copyright (C) 2025
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {@var{n} =} length (@var{tbl})
## Return the length of table @var{tbl}.
##
## For tables, the length is the maximum dimension size, which is typically
## the number of rows (equivalent to @code{max (size (@var{tbl}))}).
##
## @seealso{height, width, size, numel}
## @end deftypefn

function n = length (tbl)
  if (nargin != 1)
    print_usage ();
  endif

  ## If it's a table, return max(size(tbl))
  if (istable (tbl))
    n = max (size (tbl));
  else
    ## Fall back to built-in length() for other types
    n = builtin ("length", tbl);
  endif
endfunction

