I don't know if anybody will find this useful, but this is something I
wrote a while ago (damn NYU servers don't allow Google indexing).
It's an idea taken from Lush <http://lush.sf.net>: namely, to allow
integration of C into your LISP* code. Pretty cool if you need to talk
to the real world.
Here's an example of using it to interface with GSL and BLAS to find
the eigenvalues of a symmetric matrix:
(load "cinline")
(defun symm-eigenvals (matrix)
(let* ((n^2 (length matrix))
(n-r (multiple-value-list (floor (sqrt n^2))))
(n (if (zerop (cadr n-r)) (car n-r) (error "matrix
isn't square")))
(eivals (make-array n :element-type 'double-float)))
(cin:cinline ((double* matrix) (uint n) (double* eivals))
"""
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
"""
"""
gsl_matrix_view m = gsl_matrix_view_array ($matrix, $n, $n);
gsl_vector_view o = gsl_vector_view_array ($eivals, $n);
gsl_eigen_symm_workspace *w = gsl_eigen_symm_alloc ($n);
gsl_eigen_symm (&m.matrix, &o.vector, w);
gsl_eigen_symm_free (w);
"""
("gsl" "blas"))
eivals))
==> SYMM-EIGENVALS
(symm-eigenvals (make-array 4 :initial-contents #(1d0 2d0 2d0 1d0)
:element-type 'double-float))
==> #(3.0000000000000004d0 -1.0000000000000002d0)
Check it out under "Inline C" at http://home.nyu.edu/~ys453/
* Currently only CMUCL and SBCL work.
-Yury
It is a cool idea, but it is not a Lush idea. KCL did it ages ago (and
GCL, and ECLS do it now as well).
Details differ of course.
Cheers
--
Marco
> Corman does this, too.
Hey, now we can add CMUCL & SBCL to that list.
Cheers
--
Marco