guile-user
[Top][All Lists]
Advanced

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

Re: calling scheme procedures by name from C


From: Linas Vepstas
Subject: Re: calling scheme procedures by name from C
Date: Sun, 2 Aug 2009 06:17:04 -0500

2009/8/2 Richard Shann <address@hidden>:
> Hi,
> I want to call a scheme procedure with four arguments from C.
> (The example scheme procedure here is just displaying its arguments.)
>
> (define (d-UploadRoutine a b c d)
>  (display a)
>  (display b)
>  (display c)
>  (display d))
>
> But I can't find what the correct parameters types are -

guile is not typed, or rather, is typed at runtime only, or dynamically typed.

> the headers
> just say SCM, here are three things that give errors, two commented out
>
>
> SCM proc =  gh_str2scm("d-UploadRoutine",  strlen("d-UploadRoutine"));

The gh_* routines are old and deprecated, and have been for about
a decade now .. don't use them.

On the other hand, I notice that the tutorial at
http://www.gnu.org/software/guile/docs/docs.html
still uses gh_, so clearly, the gnu docs need cleanup :-(

> // proc = scm_string_to_symbol("d-UploadRoutine");
> // proc = scm_string_to_symbol( gh_str2scm("d-UploadRoutine",  
> strlen("d-UploadRoutine")));
> SCM arg1 =  gh_str2scm("hello", strlen("hello"));
> SCM arg2 =  gh_str2scm("he2lo", strlen("hello"));
> SCM arg3 =  gh_str2scm("he3lo", strlen("hello"));
> SCM arg4 =  gh_str2scm("he4lo", strlen("hello"));
> scm_call_4(proc, arg1, arg2, arg3, arg4);
>
> The three definitions of proc lead to the following three error messages:
>
> ERROR: In procedure apply:
> ERROR: Wrong type argument in position 1: "d-UploadRoutine"

google suggests that you read

http://www.lonelycactus.com/guilebook/x220.html
and
http://lonelycactus.com/guilebook/c1204.html

which I think is a start, and should get you going.

There's more stuff in
http://www.gnu.org/software/guile/manual/html_node/Programming-in-C.html

but it lacks examples.

> It seems to me the docs are rather deficient here!

The examples are particularly so.

> They don't give the types of the
> arguments, and the header only tells you they are SCM...

scheme is like perl, in that the types are determined during
runtime.  This is considered to be a "strength", in that, in principle,
you can define a routine that does the "right thing" for any type.

--linas




reply via email to

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