Call .NET Libraries from Lisp Using RDNZL

A long standing complaint about Lisp is the lack of high quality libraries. While the truth of this is disputed, there is certainly value in having access to the wide array of libraries found in the .Net platform.

RDNZL gives Lisp programmers access to the .NET library on the Windows platform. While other CLR implementations such as Mono are not currently supported, the maintainers of RDNZL are accepting patches for these platforms.

On the Lisp side, this library support Corman Common List, ECL, Allegro, and LispWorks. Ports for SBCL and GNU CLISP are still in progress.

RDNZL handles the basics like object creation, .NET style arrays, enumerations, boxing, .NET/Lisp type conversions, and the like with relative ease. Method calls can be done in one of two ways. The easiest way is to use the Lisp function invoke, property, or field. These methods use reflection to call the underlying .NET method. To avoid reflection, and cut the call time in half, developers can use define-rdnzl-call to create a Lisp wrapper around the call.

The most serious performance impact from using this library is the cost of marshalling data across. For that reason it is preferable to limit the number of cross-platform calls, and one should especially avoid calling .NET code from Lisp in a tight loop.

Since CLR Callable Wrappers can be easily created for COM libraries, RDNZL also gives developers access to the extensive collection of COM libraries available on the Windows platform. Examples on the link page include calling Excel objects via Microsoft Office automation from Lisp.

Event handlers and other delegates are created by passing in a Lisp closure to the delegate's constructor. One has to be careful about doing this however, as it can create a circular reference that will interfere with both the Lisp and .NET garbage collectors.