guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A little guile query.


From: Neil Jerram
Subject: Re: A little guile query.
Date: Sat, 27 Nov 2004 15:02:56 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041007 Debian/1.7.3-5

Noufal Ibrahim wrote:
Hello everyone, I have a question regarding calling C functions with REST arguments. Basically, I have a 2D array made using
      (define foo (create-array (make-array 0 10 10))

      And then I do a
(array-set! foo 1 5 5 )

      Now, to access this element from the scheme side of the program, I
can do (array-ref foo 5 5)
      And I get a 1

      What I want to know is how do I frame the C equivalent of this
array reference.
      The problem is that the function needs to accept a REST argument
that contains the indices of the array. How do I do this?
      
scm_uniform_vector_ref(scm_c_lookup("foo"),SCM_LIST2(SCM_MAKINUM(5),SCM_MAKINUM(5)));

errors out saying ERROR: Wrong number of arguments to uniform-vector-ref

Any sample code snippets on how to do this? Thank you.

Noufal,

I think the problem is actually the first arg. scm_c_lookup returns a variable which holds your array, not the array itself; you need to add scm_variable_ref to fix this:

scm_uniform_vector_ref(scm_variable_ref(scm_c_lookup("foo")),
                       SCM_LIST2(SCM_MAKINUM(5),SCM_MAKINUM(5)));

(Guile's uniform array and vector code is rather bad about spotting args that are not actually arrays or vectors!)

Regards,
     Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]