Arrays in the Common Lisp standard can be multidimensional.
Array Dictionary describes the available operations.
CL-USER 12 > (defparameter *a* (make-array '(3 2 4) :initial-element 'foo)) *A* CL-USER 13 > *a* #3A(((FOO FOO FOO FOO) (FOO FOO FOO FOO)) ((FOO FOO FOO FOO) (FOO FOO FOO FOO)) ((FOO FOO FOO FOO) (FOO FOO FOO FOO))) CL-USER 14 > (setf (aref *a* 1 1 2) 'bar) BAR CL-USER 15 > *a* #3A(((FOO FOO FOO FOO) (FOO FOO FOO FOO)) ((FOO FOO FOO FOO) (FOO FOO BAR FOO)) ((FOO FOO FOO FOO) (FOO FOO FOO FOO))) CL-USER 16 > (array-dimensions *a*) (3 2 4)
When working with arrays, it may be useful to use another Common Lisp function: type declarations and compiler optimization. Generic Lisp allows you to write generic code without declaring types. But in critical sections you can declare types of variables, parameters, return values, etc. Then you can instruct the compiler to get rid of some checks or use type operations. The amount of support depends on the compiler. There are more complex compilers, such as SBCL, LispWorks, and Allegro CL, which support a wide range of optimizations. Some compilers also provide great compilation information.
The last resort is to use an external function interface (FFI) to invoke C code or use the built-in assembler (which is supported by some compilers).
Generic Lisp has a default LOOP macro in the standard. This allows us to express typical designs of planing cycles. There is also an alternative, the ITERATE macro - it may have some advantages for multidimensional arrays.
Also note that Lisp arrays have some unusual functions, such as relocated arrays. They use storage of some other array, but can have a different format.
Sometimes it is also useful to write special macros that hide the pattern of using arrays. Without this, Lisp code with declarations like multidimensional arrays and LOOPs can be a little big. An example of typical code that does not use special linguistic abstractions is given here: fft.lisp .
The special use of SIMD instructions or other forms of parallelism data is usually not provided by Common Lisp compilers out of the box. Exceptions may exist.
Rainer joswig
source share