wants with-callback

Bug #1834126 reported by Chen Ruofan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
Triaged
Wishlist
Unassigned

Bug Description

Hi, I'm writing some Common Lisp numerical integration routines. These routines call numerical integration routines in GSL. Therefore callback need to be given to GSL routines.

The ideal way to do it is to build a callback and then pass it to GSL routines. And this callback is dismissed after the evaluation, in other words, with-callback is needed.

Right now, I define a global callback which holds the function which is to be integrated. It works, but obviously it is not thread safe. This is the reason why I want with-callback.

It would be better if we can define anonymous callback and pass it like an ordinary function.

Best Regards

Revision history for this message
Luís Oliveira (luismbo) wrote :

若凡你好!

Some Lisps support anonymous callbacks (e.g., SBCL's sb-alien:alien-lambda) but not all. Nevertheless, it'd be nice for CFFI to support that when possible. Marking this bug as wishlist item.

You may be able to work around this by reusing the same callback each time and using the dynamic scope. Something along these lines:

  (defvar *foo*)

  (defcallback bar ... (do-something-with *foo*))

Then:

  (let ((*foo* <something>))
    (your-foreign-funcation (callback bar)))

BTW, have you seen Liam Healy's GSLL <https://common-lisp.net/project/gsll/>?

Changed in cffi:
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Chen Ruofan (physcrf) wrote :

Luismbo 你好!

I once read this kind of dynamic scope code in CL-PDF, but at that time I didn't understand it. Thanks for your suggestion.

And I know GSLL. In fact, I have searched scientific libraries in Common Lisp in Cliki. There are some libraries impressed me such as LLA, LISPLAB, LISP-MATRIX, MATLISP and GSLL etc al.

However, LLA is not under maintained anymore, its author switch to Julia from Common Lisp <https://tpapp.github.io/post/common-lisp-to-julia/>. In LLA, seems matrix is stored in Lisp array and copy to foreign memory when call BLAS routines.

LISPLAB seems not support matrix slice and it is lightweight.

LISP-MATRIX can store data in Lisp array and foreign array. However, in numerical calculation I think store in Lisp array is unnecessary.

MATLISP seems under maintain but lacks documentation. While its design is a little bit sophisticated. Its speed for some basic BLAS operation seems not fast, maybe they are written in Lisp function rather than calling libblas routine.

Above libraries have a common shortcoming, at least shortcoming for me, that their function names are too general and brief. They try to provide syntactic sugar and be clever at early stage. However, for scientific calculation I think stable and speed are of more importance and scientific library should be "stupid" and solid. For example, function names in GSL itself is long but with clarification.

And for GSLL, in fact I tried to use GSLL to do scientific calculation. However, its matrix is represented by Antik. Antik is an interesting and powerful library but it lacks documentation. Besides, it also tries to be clever and with syntactic sugar at early stage.

What's more, GSL is designed for C. Although it covers most regions of scientific calculation, not all of its routines need to be wrapped for Common Lisp. And for matrix calculation I think directly calling BLAS and LAPACK or OpenBLAS is better. For fast fourier transform FFTW may be better.

Therefore I'm trying to organize a new scientific library with numerical integration routines even which are defined in GSLL.

BTW, I'm also looking forward for C99 Complex type in CFFI. I see the suggestion in 2010 <https://bugs.launchpad.net/cffi/+bug/622260> but it seems not in CFFI yet. I have written a complex type definition package for CFFI <https://github.com/physcrf/complex>. I hope my code would be helpful if you want add complex type in CFFI.

At last, I appreciate CFFI and hope it would be better in future.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.