unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mike Gran <spk121@yahoo.com>
Subject: Re: Newbie question regarding REST arguments from C.
Date: Fri, 11 Jun 2004 06:56:10 -0700 (PDT)	[thread overview]
Message-ID: <20040611135610.76424.qmail@web14310.mail.yahoo.com> (raw)
In-Reply-To: <87isdy305i.fsf@cisco.com>

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

--- Noufal Ibrahim <nkv@willers.employees.org> wrote:
> 
>       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

You're misreading the meaning of the error message.  You've called the
function correctly and made the list correctly.  Its just that
scm_c_lookup doesn't return what you think it does.

The function scm_c_lookup() doesn't return the array itself.  It
returns the variable that contains the array.  From there you need to
use scm_variable_ref() to dereference the variable to get its contents.
 Its kind of like a pointer vs. the data that the pointer points to.

It says you've got "Wrong number of arguments" because the variable
that scm_c_lookup returns isn't an array, it is a single variable. 
Only its contents is an array.

Attached please find an example.


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

[-- Attachment #2: main.c --]
[-- Type: application/octet-stream, Size: 845 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>


int main(int argc, char **argv)
{
    SCM s_symbol, s_array, s_val;
    int val;
    int i, j;

    scm_init_guile();
    
    /* Set up the Guile array */ 
    scm_c_primitive_load ("data.scm");
    
    /* Lookup the array "foo" defined at top-level */ 
    s_symbol = scm_c_lookup("foo");
    s_array = scm_variable_ref(s_symbol);

    /* Check to see if it is an array */
    if (SCM_ARRAYP (s_array)) {

	for (j = 0; j < 3; j ++) {
	    for (i = 0; i < 3; i ++) {
		/* Get the Guile value at that location in the array */ 
		s_val = scm_uniform_vector_ref(s_array, 
					       SCM_LIST2(SCM_MAKINUM(i), SCM_MAKINUM(j)));
		val = scm_num2int(s_val, 0, "main");
		
		printf("foo(%2d,%2d) = %d\n", i, j, val);
	    }
	}

    }
    printf("\n");
    
    return(EXIT_SUCCESS);
}


[-- Attachment #3: data.scm --]
[-- Type: application/octet-stream, Size: 60 bytes --]

(define foo 
  (make-array 0 3 3))
(array-set! foo 10 2 2)


[-- Attachment #4: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

  reply	other threads:[~2004-06-11 13:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-11  9:38 Newbie question regarding REST arguments from C Noufal Ibrahim
2004-06-11 13:56 ` Mike Gran [this message]
2004-06-11 14:37   ` Noufal Ibrahim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040611135610.76424.qmail@web14310.mail.yahoo.com \
    --to=spk121@yahoo.com \
    --cc=spikegran@earthlink.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).