Accessing C functions from CLISP

It’s pretty impressive how easy it is to call C functions from Lisp, once you know the proper FFI voodoo. For example, this is how I accessed the standard C library function time from CLISP on my Linux system.

(ffi:def-call-out time                                                                                                       
    (:arguments (tloc (ffi:c-ptr-null ffi:int) :in))                                                                           
    (:library "/lib/")                                                                                                
    (:return-type ffi:int))

CL-USER> (time nil)                                                                                                        

Historically, different Lisp implementations have had different FFI syntax though there are things like UFFI and CFFI that are supposed to ameliorate that.

And depending on what Lisp you’re using, you might be able to use SWIG to jumpstart the process.

Books on Lisp from

The Little Schemer - 4th EditionThe Seasoned SchemerPractical Common Lisp

Leave a Reply

Your email address will not be published.