function s = sum (x, dim)

  if (nargin < 1 || nargin > 2)
    print_usage ("sum");
  endif

  if (nargin == 1)
    s = builtin ("sum", x);
  else
    if (! isnumeric (dim) || ! isvector (dim))
      error ("sum: DIM must be a numeric scalar or vector");
    endif
    s = builtin ("sum", x, dim(1));
    for i = 2:numel (dim)
      s = builtin ("sum", s, dim(i));
    endfor
  endif

endfunction
