On Sun, 2009-08-02 at 06:17 -0500, Linas Vepstas wrote: > 2009/8/2 Richard Shann <richard.sh...@virgin.net>: > > 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 This seems to do the trick - I googled without finding anything so useful, but I am a dreadful googler. The lines I needed were these:
func_symbol = scm_c_lookup("do-hello"); func = scm_variable_ref(func_symbol); > 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. Unfortunately, the writer of scm_call_4 did not choose to define the routine to do the right thing for any type I tried! And as the docs didn't even give the C-prototype (which anyway only tells me it takes SCMs) I cannot call the function without looking at the implementation. Or asking the ever helpful band of schemers! Thank you very much for such a speedy & informative reply. Richard > > --linas