freenode/#lisp - IRC Chatlog
Search
2:19:51
z3t0
how do people generally deal with the lack of libraries for lisp? for the most part I don't have an issue but when trying to use something like opencv (computer vision) or graphics I have a lot of trouble with common lisp
2:20:27
z3t0
Some of these have c bindings so i can use cffi but often they have c++ bindings. I looked up swig but it seems that it only supports allegro common lisp
2:26:23
z3t0
ebrasca: I could definitely do that but I have no idea where to start, how do I write a common lisp wrapper for a c++ library?
2:26:58
z3t0
I did some searching before and basically was led to the conclusion that it wasn't a realistic project for a sufficiently complex project
5:08:20
pillton
Or you could compile the C++ library to web assembly and interpret the webassembly in common lisp.
5:08:28
beach
z3t0: I totally agree. But then, sometimes you have to bite the bullet and write a library.
5:13:56
beach
z3t0: I don't think that was a joke. I think that must be what froggey does in order to run C code in Mezzano. No?
5:16:08
pillton
I wasn't joking. It is a better strategy long term in my opinion. CFFI allows the foreign function to crash the lisp process.
5:18:21
aeth
If you don't care at all about performance, it wouldn't be that hard to compile C to Lisp, would it?
5:19:17
aeth
You wouldn't benefit from the optimizing compilers (unless you write a CL backend for LLVM somehow?) but it would probably beat WASM.
5:19:54
aeth
I think that's what Mezzano does, although I'm not sure how. C is much easier than C++, though, unless you're using LLVM.
5:25:42
White_Flame
the problem is that too many things rely on C undefined behavior that automated translation to another safer language wouldn't respond the right way
5:25:56
aeth
I'm guessing you'd be dealing with giant byte arrays. Then the question is if you can somewhat efficiently deal with e.g. floating point operations.
5:27:24
aeth
so if your giant pile of bytes is supposed to deal with floating point, how do you do foo.x + foo.y, which becomes 1.0f + 2.5f?
5:29:26
aeth
I think that ties in with safety. (floating-point-to-byte (+ (byte-to-floating-point x) (byte-to-floating-point y))) isn't going to be fast, but that isn't an issue in C where you can do things like fast inverse square root. https://en.wikipedia.org/wiki/Fast_inverse_square_root
5:30:28
aeth
I think you would need implementation-level support to optimize away common special cases like floating point if you really wanted to do CFFI that way.
5:33:40
aeth
If someone did the LLVM IR to CL approach, I'd be interested in seeing them run Clasp on it, though.
6:25:38
pjb
aeth: theorically, it's not hard to compile C to Lisp. In practice, it only represents a lot of work. I started such a compiler. I have the pre-processor implemented. The size of the work comes from the fact that you want not just "a" C compiler, but you actually need a compiler with all the syntax and extensions supported by gcc/clang. Because you don't want to have to "port" your libraries, you want them to just run as-they
6:26:50
pjb
Perhaps I should do a kickstarter to finance the development of this C-to-Lisp compiler… I'd say it'd cost 15000 to 30000 euro.
6:28:01
White_Flame
I think it might be easier to take C source + debug information + a compiled library, and "transpile" the x86 code to lisp image compatible code
6:34:03
pjb
White_Flame: the thing is that it may be harder to restore source-level information from the binary.
6:35:23
pjb
The point here is that we want to use C libraries in a controlled environment. So compiling from C source to the controlled lisp VM environment, or transpiling from a native code that is full of uncontrolled pointer action, to a controlled lisp VM environment. The later doesn't sound the easy way.
7:03:00
|3b|
looks like it sets first 3 FDs to *standard-input* *standard-output* *error-output*, and has a customized SDL on c side for graphics (that can write to mezzano or lispbuilder-sdl on lisp side)
7:10:11
pjb
pillton: for "standard" C functions, you can either forward to libc, or implement them in lisp. From the TODO, I'd guess he calls libc.