From: Roel Janssen <roel@gnu.org>
To: Jean Rene Dawin <jdawin@math.uni-bielefeld.de>, guile-user@gnu.org
Subject: Re: Difference when calling guile script from C vs interpreter
Date: Tue, 20 Oct 2020 16:37:22 +0200 [thread overview]
Message-ID: <2f0278dd3fe46bcd9ae4b79b2ba466bea857ef8a.camel@gnu.org> (raw)
In-Reply-To: <a4e5ab0a-1733-42c0-05cc-3e5100914048@gmail.com>
On Tue, 2020-10-20 at 16:27 +0200, Taylan Kammer wrote:
> On 20.10.2020 14:58, Jean Rene Dawin wrote:
> > Hi,
> >
> > when following guile script:
> > ______ gp.guile _________
> >
> > (snip)
> > ______________________________
> >
> > is run from the interpreter, the output shows the following:
> >
> > (snip)
> > Total time: 0.327908556 seconds (0.121140347 seconds in GC)
> > #t
> >
> >
> >
> > When the same script is loaded from following C program:
> > _____ gp.c _______
> > #include <libguile.h>
> >
> > int main(int argc, char **argv)
> > {
> > scm_init_guile();
> > scm_c_primitive_load("/home/gp.guile");
> > return 0;
> > }
> > ___________________
> >
> > the result looks like this:
> >
> > (snip)
> > Total time: 1.939099187 seconds (0.570765622 seconds in GC)
> > #t
> >
> > Is this difference expected?
>
> When you use the "guile" executable to run a file, it automatically
> compiles it first, then runs the compiled version. (For this reason
> I
> wouldn't use the term "interpreter" in this case.)
>
> When using primitive-load, it doesn't auto-compile it (and I think it
> doesn't even look for an already compiled version), instead it
> directly
> calls the interpreter on the source code. (This time it really is
> the
> interpreter.)
>
> It's generally preferable to *extend* Guile with C code, rather than
> to
> *embed* it in C code. This means you turn your C code into
> libraries,
> which are turned into Guile modules, then you write a Guile program
> that
> uses those modules. I.e. you call to C code from Guile, not to Guile
> code from C.
>
> If you want to really prefer to embed and not extend, then perhaps
> you
> can make your Guile files available in the %load-path and use
> scm_primitive_load_path (see documentation).
>
> I don't know if/how the Guile compiler can be called from C. Maybe
> someone more experienced can help further.
>
>
> - Taylan
>
>
Once you've compiled the Guile module, it should be enough to set the
GUILE_LOAD_COMPILED_PATH environment variable before booting Guile in
C. Here's what I use:
https://github.com/UMCUGenetics/sparqling-genomics/blob/master/web/sg-web.c.in#L314-L356
Kind regards,
Roel Janssen
next prev parent reply other threads:[~2020-10-20 14:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 12:58 Difference when calling guile script from C vs interpreter Jean Rene Dawin
2020-10-20 14:27 ` Taylan Kammer
2020-10-20 14:37 ` Roel Janssen [this message]
2020-10-21 11:32 ` Jean Rene Dawin
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=2f0278dd3fe46bcd9ae4b79b2ba466bea857ef8a.camel@gnu.org \
--to=roel@gnu.org \
--cc=guile-user@gnu.org \
--cc=jdawin@math.uni-bielefeld.de \
/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).