The AplArray class holds array data and shape information. It also defines functions that are fundamental to the array, such as Shape and Reshape. Shape and Reshape will also be defined in the function layer, but will return a different type of object, as will be explained below.
The properties of an AplArray are its shape and data. The shape is always a simple (1-d, non-nested) list. If the data is a scalar, then shape is an empty list. Interestingly, if the data is an empty list, then the shape is [0]!
The data is stored either as an int, float, single-character string, multi-character string, or a list. An int or a float is always a scalar, with shape []. A list or multi-character string has a shape of at least one dimension. Note that a single character string can have either no shape [] or a finite shape. In APL2, the user can enter a single character as a scalar or as a single element array. Python treats single characters as a single character array. The only way to distinguish the shape is by examining the shape property.
The AplArray.Shape(self) function simply returns the shape property as a single integer or list of integers.
The AplArray.Reshape(self,newshape) function reshapes the AplArray with newshape, a list of integers. The data array is shortened or lengthened so that the total number of elements is just enough to fill the shape. The data list itself remains a simple Python list.
The Shape and Reshape functions are defined in the AplArray class layer because these functions are fundamental to the shape and contents of the array. Here, these functions return Python lists (or scalar data) so that they can be directly manipulated with Python functions. These functions will also be implemented as static functions in the function layer of the APyL2 implemented. At the function layer, the Shape function will return an AplArray object.
A few other functions may have to be implemented at the AplArray class level as well, but these will be limited to functionals fundamental to the shape and contents of the array. For example, certain specification operations may want to be implemented here. In any case, any APL intrinsic function that is implemented at the AplArray class layer will also be implemented in the function layer.