unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Linas Vepstas <linasvepstas@gmail.com>
To: richard.shann@virgin.net
Cc: guile-user@gnu.org
Subject: Re: calling scheme procedures by name from C
Date: Sun, 2 Aug 2009 06:17:04 -0500	[thread overview]
Message-ID: <3ae3aa420908020417nd62c8ffw28fec741c26a81cc@mail.gmail.com> (raw)
In-Reply-To: <1249204627.2918.56.camel@debianrts.home>

2009/8/2 Richard Shann <richard.shann@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
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	other threads:[~2009-08-02 11:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-02  9:17 calling scheme procedures by name from C Richard Shann
2009-08-02 11:17 ` Linas Vepstas [this message]
2009-08-02 12:03   ` Richard Shann
2009-08-02 15:00   ` Mike Gran
2009-08-02 17:22     ` Linas Vepstas
2009-08-02 18:08       ` Daniel Kraft
2009-08-02 19:15         ` Linas Vepstas
2009-08-02 19:37           ` Daniel Kraft
2009-08-02 20:07             ` Linas Vepstas
2009-08-13 23:19           ` Updated Guile Tutorial Neil Jerram
2009-08-02 13:00 ` calling scheme procedures by name from C Paul Emsley
2009-08-02 13:35   ` Richard Shann
2009-08-02 19:51   ` Peter TB Brett

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=3ae3aa420908020417nd62c8ffw28fec741c26a81cc@mail.gmail.com \
    --to=linasvepstas@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=richard.shann@virgin.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).