This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gh_scm2doubles and friends


I think your suggested interface is too complex.  One of the goals of
the gh interface is that it should be easy to use.

The current interface looks like this:

 - Function: double *gh_scm2doubles (SCM VECTOR, double *RESULT)
     Copy the numbers in VECTOR to the array pointed to by RESULT and
     return it.  If RESULT is NULL, allocate a double array large
     enough.

Here's how you would solve your three tasks using this interface:

SCM example(SCM myvect) {
    double *mem = NULL;
    int i, n = gh_length(myvect);
    mem = gh_scm2doubles(myvect,NULL);
    some_function(mem,n);
    for (i = 0; i < n; ++i)
      SCM_VELTS (myvect)[i] = gh_double2scm (mem[i]);
    free (mem);
    return myvect;
}

SCM example(SCM myvect) {
    double newvect;
    double *mem = NULL;    
    mem = gh_scm2doubles(myvect,NULL);
    some_function(mem,gh_length(myvect));
    newvect = gh_doubles2scm(mem);
    free (mem);
    return newvect;
}

SCM example(SCM myvect) {
    some_function(SCM_VELTS (myvect),gh_length(myvect));
    return myvect;
}

Isn't this pretty OK?  (Except maybe that SCM_VELTS isn't part of the
gh interface...)

Best regards,
/mdj