[plt-scheme] simple ffi problem

From: Mike Miller (mike at nec-labs.com)
Date: Thu Jul 21 18:32:24 EDT 2005

I've successfully interfaced with the external C function:

   double fun1 (int in1);

using the scheme code:

   (require (lib "foreign.ss"))

   (define fun1
     (get-ffi-obj "fun1" "myclib"
                  (_fun _int -> _double)))

I needed (unsafe!) to make the get-ffi-obj procedure visible.

Now I have a C arrays of doubles (double *) that I want to use safe C  
vectors (cvector) with, for efficiency.

However, I can't get the syntax right for the external C function:

   void fun2 (int in1, double *arr);

I've tried:

   (define fun2
     (get-ffi-obj "fun2" "myclib"
                  (_fun _int _cvector -> _void)))


   (define fun2
     (get-ffi-obj "fun2" "myclib"
                  (_fun _int (_cvector i _double) -> _void)))

but keep getting errors like:

   procedure application: expected procedure, given: #f;
     arguments were: #<struct:fun-syntax> #<syntax:36:26>

I don't get an error if I use _vector instead of _cvector, but that's  
not the data type I want.

If it matters, I'm trying this under Mac OS X.

Thanks in advance for helping this novice to ffi.

Posted on the users mailing list.