## 5 Discussion

### 5.1 The foreign function interfaces

The foreign function interface comes from Matlisp and
is mainly on level 3.
The elements of Lisplab typed matrices (double-float and complex double-float) are
stored as 1D simple arrays, and most Lisps will then have
a SAP inside the array pointer which is binary compatible
with Fortran. This adds some overhead to matrix element references,
but simplifies the memory management considerably compared to a bare pointer type.
Also, it is important to avoid pointers from being moved
by the garbage collector. In Matlisp, this was handled by stopping
the garbage collector, but a more smoother and better way would be to
just pin the pointers in action.

Lisplab has an extra layer with Fortran compatibility above
the ordinary C FFI. This layer is mainly unchanged compared
to Matlisp, but only the SBCL FFI is distributed with Lisplab.

The FFI for FFTW is a mock-up for SBCL, and it only is for standard
complex transforms and inverse transforms. Of course, a lot more can
be done, but this simple version works quite OK. In long term the SBCL
FFI should be replaced with a general one.

### 5.2 Parallel execution

To request usage of more threads, call `init-threads`

.
Currently only the calls to FFTW will react to this.

### 5.3 Symbolic calculations

There is draft code for symbolic calculations, but it is not yet included
in the build. The symbolic code need not know anything about the rest of Lisplab,
except for the generic methods of the dotted algebra (The level 0).

### 5.4 Missing features

- There is no way to iterate through the elements of
a general matrix in a fast way. (The map functions are currently the only
thing, but these are structure agnostic and also not fast.) There
should maybe be an macro
`w/matrix`

.
- There should be linear algebra primitives, like row exchange,
in level 2, so that level 3 can be made entirely without knowledge about
internal structure of matrices. (Structure similar to blas - lapack)
- Integer matrices.
- Vectorized execution of operations.
- Numerical integration.
- Symbolic math. Should be separate module, only with knowledge
of the dotted algebra generic functions.
- The dotted algebra should also work on functions
so the one could write
`(.+ (lambda (x) (+ x 1)) 3)`

and get a new functions as result. It might even
be possible to make beautiful optimizations this way.