Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

> Then again, in Common Lisp it’s somewhat rarer to have C extensions, so I don’t know how ASDF handles that.

CFFI

https://common-lisp.net/project/cffi/



Besides CFFI there's also cl-autowrap and claw. I haven't used claw myself, but I know cl-autowrap makes wrapping C libraries really easy. It took me about 4 hours and <200 lines of code to have a complete, usable binding for GDAL, and most of that was in convenience functions.

I'm curious to see what happens with the C++ support in claw. They're working on it, but I'm skeptical. I haven't had much luck using arbitrary C++ libraries from any language other than C++.

And I don't know what the author means by "somewhat rarer" in this context, but I personally use C libraries from CL all the time. Almost every CL project I work on, now that I think about it.


:claw author reporting in. At first, I was semi-skeptical too, but not anymore. I've managed to wrap a few C++ libraries (GLM, Filament, PhysX). Not without a manual intervention (claw is still evolving and adapting to C++ edge cases), but those libraries pretty much work now. I'm not sure I would be able to cover all C++ idiosyncrasies, but huge parts are already in.

That said, claw's C++ support is still in the works and I don't recommend diving into that mess yet. Stay tuned for Q1 2021 semi-usable alpha release. Or not. C++ is such a pile of shinies, I'm pretty sure I lost a few screws during :claw development.


I'll have to take another look!

Very surprised to see GLM in that list!


Rarer? How? Why? I know multiple people who do it daily. A lot of Lisp code directly depends on foreign libraries.


Actually I was talking about how to bundle C code with a Common Lisp library (or system), so that ASDF could also handle building it.

Guile has a C API in libguile, so you can create C that's directly callable from Scheme with little overhead. You can write Scheme procedures in C and you don't need to gobthrough FFI.

As far as I know both languages have FFI. CL has CFFI, Guile has it in its standard library.

But can I actually ship some C code with my CL system and have ASDF take care of building it? If I want to ship CL bindings for a C library, as far as I've understood I need to tell users to install the library first. Maybe something like Clasp offers a C++ API?

Then again in both languages you can always use FFI and if things get hairy you can use grovelling.

With Guile, it's really easy to have a C library and package its guile bindings in the same place. Not saying you can't do this in CL, just that I don't know what it would look like to ship both C and CL in the same package.

(author)


Someone requested to add a project to Quicklisp; that project does just what you describe. See the ASD file for details.

https://github.com/tdrhq/cl-unix-sockets


a bit about the context:

Guile is an extended specific implementation of Scheme. Common Lisp OTOH is a language standard with widely different implementations. Just like Scheme has very different implementations - in sizes of small, medium and large.

Common Lisp with more extensive C extension support are CLISP (written in C, not that well supported nowadays), ECL ('embeddable Common Lisp', compiling to C), CLASP (integration with C++ via LLVM), mocl (commercial whole program compiler to C) and a bunch of others.

Thus the support of and integration into is different in Common Lisp implementations, just like it is different in Scheme implementations. GUILE was designed for C embedding, just like some Common Lisp implementations were designed for that task. Guile was also designated as a language of choice for the GNU project, which adds quite a bit community support - while Common Lisp (or one of its implementation) was not:

'Guile is the GNU Ubiquitous Intelligent Language for Extensions, and the official extension language of the GNU project.'


Yeah, this. I call C code from CL all the time. Also Objective C if I'm working with Clozure CL on a Mac.


In Guile, because it lacks an optimizing native code compiler, they write C extensions just to get their code to perform acceptably. In Common Lisp the only reason you'd use CFFI is if you needed to call some code that was written in C.


That's not quite true anymore: Guile 3.0 has an optimizing compiler and a JIT and it performs pretty well.

See for instance: https://wingolog.org/archives/2019/06/26/fibs-lies-and-bench...

Nowadays most Guile users write exclusively Scheme code, resorting to the FFI for code reuse rather than for performance reasons.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: