[ Term Manipulation | Reference Manual | Alphabetic Index ]
# dim(?Term, ?Dimensions)

Creates a multi-dimensional array in the form of nested structures,
or computes the dimensions of an existing matrix.
*Term*
- Variable or structure.
*Dimensions*
- Variable or list of integers.

## Description

Creates a multi-dimensional array in the form of nested structures,
or computes the dimensions of an existing matrix.
When creating an array of dimensions [D1,..,Dn], a nested structure
is created with the top-level term having the functor []/D1, its
arguments being structures with functor []/D2, and so on.
The functor [] is chosen to remind of arrays, but is otherwise
not significant.

To get the size of one-dimensional arrays, it is more efficient to
use arity/2.

### Modes and Determinism

- dim(+, -) is det
- dim(-, ++) is det

### Exceptions

*(4) instantiation fault *
- Both Term and Dimensions are not sufficiently instantiated.
*(5) type error *
- Dimensions is not a list of integers.

## Examples

[eclipse]: dim(M,[3,4]), dim(M,L).
M = []([](_131, _132, _133, _134),
[](_126, _127, _128, _129),
[](_121, _122, _123, _124))
L = [3, 4]
yes.

## See Also

arg / 3, arity / 2, subscript / 3, flatten_array / 2, functor / 3