From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Roel Janssen Newsgroups: gmane.lisp.guile.user Subject: Re: Difference when calling guile script from C vs interpreter Date: Tue, 20 Oct 2020 16:37:22 +0200 Message-ID: <2f0278dd3fe46bcd9ae4b79b2ba466bea857ef8a.camel@gnu.org> References: <20201020125840.GA14718@math.uni-bielefeld.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4193"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.1 (3.38.1-1.fc33) To: Jean Rene Dawin , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Oct 20 16:40:14 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kUso8-0000wA-7G for guile-user@m.gmane-mx.org; Tue, 20 Oct 2020 16:40:12 +0200 Original-Received: from localhost ([::1]:39410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUso7-000560-6E for guile-user@m.gmane-mx.org; Tue, 20 Oct 2020 10:40:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUslT-0001wL-OO for guile-user@gnu.org; Tue, 20 Oct 2020 10:37:27 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:56594) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUslR-0001Vl-ON; Tue, 20 Oct 2020 10:37:25 -0400 Original-Received: from [143.121.239.12] (port=40566 helo=[10.132.152.6]) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kUslQ-0006lo-Op; Tue, 20 Oct 2020 10:37:25 -0400 In-Reply-To: X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16991 Archived-At: 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 > > > > 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