<!-- <a style="font-size: 120%" href="https://www.udemy.com/course/common-lisp-programming/?couponCode=LISPY-XMAS2023" title="This course is under a paywall on the Udemy platform. Several videos are freely available so you can judge before diving in. vindarel is (I am) the main contributor to this Cookbook."> Discover our contributor's Lisp course with this Christmas coupon.</a> -->
📢 New videos: <ahref="https://www.youtube.com/watch?v=h_noB1sI_e8">web dev demo part 1</a>, <ahref="https://www.youtube.com/watch?v=xnwc7irnc8k">dynamic page with HTMX</a>, <ahref="https://www.youtube.com/watch?v=Zpn86AQRVN8">Weblocks demo</a>
<p>The ANSI Common Lisp standard doesn’t mention this topic. So almost everything that can be said here depends on your OS and your implementation. However these days, we can use the <ahref="https://github.com/cffi/cffi">CFFI</a> library, a portable and easy-to-use C foreign function interface.</p>
<p>CFFI, the Common Foreign Function Interface, purports to be a portable FFI for Common Lisp. It abstracts away the differences between the API of the native FFI’s of the various Common Lisp implementations.</p>
<p>Let’s use <code>defcfun</code> to interface with the foreign <ahref="https://en.cppreference.com/w/c/numeric/math/ceil">ceil</a> C function from <code>math.h</code>.</p>
<p><ahref="https://cffi.common-lisp.dev/manual/html_node/defcfun.html">defcfun</a> is a macro in the cffi library that generates a function with the name you give it.</p>
<p>We say that the “ceil” C function will be called “c-ceil” on our Lisp side, it takes one argument that is a double float, and it returns a number that is also a double float.</p>
<p>The reason we called it <code>c-ceil</code> and not <code>ceil</code> is only for the example, so we know this is a wrapper around C. You can name it “ceil”, since it doesn’t designate a built-in Common Lisp function or macro.</p>
<p>Let’s try another one! This time, we’ll use <ahref="https://en.cppreference.com/w/c/numeric/math/floor">floor</a>, and we couldn’t name it “floor” because this Common Lisp function exists.</p>
📹 Discover <astyle="color: darkgrey; text-decoration: underline",href="https://www.udemy.com/course/common-lisp-programming/?referralCode=2F3D698BBC4326F94358">our contributor's Common Lisp video course on Udemy</a>