1
2# This function returns the "shape" (that is, the dimensions) of the
3# entity `x'.  If `x' is a scalar, it returns NULL.  If `x' is a
4# vector, it returns a scalar having the length of `x' as its value.
5# If `x' is a matrix, it returns a vector having the number of rows
6# and the number of columns as its first and second elements,
7# respectively.  If `x' has any other class, an exception is raised.
8
9shape = function (x)
10{
11  return self.(class(x)) (x);
12};
13
14( shape.table =
15  shape.("function") =
16  shape.("NULL") = strip (
17    function (x)
18    {
19      message ("run time error:  Invalid %s argument for shape."; class (x));
20      exception ();
21    })
22);
23
24shape.scalar = function (x) { return NULL; };
25shape.vector = function (x) { return x.ne; };
26shape.matrix = function (x) { return x.nr, x.nc; };
27