BT

Call .NET Libraries from Lisp Using RDNZL

by Jonathan Allen on Aug 22, 2007 |

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.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Good stuff! by Kurt Christensen

The author of RDNZL (Ed Weitz) has produced some other high-quality stuff. For non-Lispers, I highly recommend his "Regex Coach", a really sweet GUI regex tool, written in Lisp.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT