[Larceny-users] ffi support for Integer to float

Felix Klock felixluser at pnkfx.org
Sat Feb 7 12:01:09 EST 2009


Ed-

On Feb 6, 2009, at 7:23 PM, Eduardo Cavazos wrote:
>
> However, it's no fun to litter the code with 'exact->inexact'. Another
> approach I take is to do (+ 0.0 n).
>
> So my question is, in the future, will the ffi work such that numeric
> conversions such as these happen automatically? If not, then I suppose
> the solution is a "higher level" library which does things like:
>

I am not planning to change the semantics of the current conversion  
routines.

However, the FFI is extensible; you can add new type-descriptors with  
corresponding conversions.  So you could add a 'int-or-double type  
that converts fixnum inputs into flonums before passing the result  
along to the lower layer routines.

The current Larceny documentation does not describe these relatively  
new features properly (sorry), but you can look at section 4.2.2 of  
the paper I presented at the Scheme Workshop last fall for some  
information about how to go about doing this:

http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-schemeworkshop-2008.html

I also have been meaning to take some time to compare your gl  
interface to the one that I hacked up some time ago.  The main  
difference between us, I suspect, are that I use Larceny's define-c- 
info form to extract the various constants from the header file, while  
your code writes the values explicitly as Scheme definitions (which  
seems to be an entirely acceptable approach for a library like OpenGL  
where the values of the constants do not change over time).

-Felix






More information about the Larceny-users mailing list