From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: Guile + SWIG Date: Mon, 5 Apr 2021 16:51:35 -0700 Message-ID: References: <65bb42ce8d587b284b70d48f2f4b0c99e5c37cf7.camel@mrc-lmb.cam.ac.uk> <2a6711742cea0cf53342f70a2941b26e48efd864.camel@linas.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39358"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Apr 06 01:52:29 2021 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 1lTZ1B-000A7W-3F for guile-user@m.gmane-mx.org; Tue, 06 Apr 2021 01:52:29 +0200 Original-Received: from localhost ([::1]:53802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lTZ19-00015M-Tk for guile-user@m.gmane-mx.org; Mon, 05 Apr 2021 19:52:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTZ0V-000152-GX for guile-user@gnu.org; Mon, 05 Apr 2021 19:51:47 -0400 Original-Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:42802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lTZ0R-00032b-89 for guile-user@gnu.org; Mon, 05 Apr 2021 19:51:47 -0400 Original-Received: by mail-pf1-x42b.google.com with SMTP id 11so7453074pfn.9 for ; Mon, 05 Apr 2021 16:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=+YxipfLjohrggEtdYZPve1ohMifcSwJ/13ga7yIM9mk=; b=HbNVf6oIQKKVHBu/byBZJi+JJdBDm15zgOIV/hWjmgM5GPaWkfanq2oE+xR8GRiq0/ /bTlLW5DFRO6rmqPLtpXPBefNaB33/xhro1HBYRov8kehdaJzBRkqXQn44WYWSjkKGwq cYMnf97eovP7YC7hCW3bu10A7KmxggZYHBfYTrLl/B8kOis/frJqt8gLrzPvvQNr2t4k Sla2jzQLbqkernnX46QsXaACZ+H9nIenScsuZshS+tNs3Vc/chdbYhNjzY3bxrB6Hicz vf1zjZM5bStxHW2YJFWDUlLrCUNJkot5baSdk7D0/z/A6bqRTD6wM/CtUHLz+6+oBX7f haxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=+YxipfLjohrggEtdYZPve1ohMifcSwJ/13ga7yIM9mk=; b=Fq/3W5wxwdW22nKLUBvhtk+wOf2QZszqMEP+x8tC/JgpttUMBhM9vLqjeAqmHDWpx6 VzZKBYsxkbWwNyiCUUuM1HHpLpfVRr8yxizcMLmdL3GDwRP+P5ef0lQ98YmQEEIyqXRI +2miBk+1oI9daO10BIIq3Moe5svAyixNvQ/34p8NC6JjuO3EE5eomFEZBFVer6OXGUi2 DrHs7/Igd1ds4RuHNHO5O6yZlU1BUwfgXHGqEmz5nBX5H8jmIKb4XCNYjz1G2Vlh7l9P /nQEfLUJOjULWjp4bKZItDDC3mXK3BZViHfaCTr6rvonyJOKRHyVs53ASK0tML3iOXN4 h9Fg== X-Gm-Message-State: AOAM533+ypgImaXgFwMYgiKyOw1lvQkJR2NIM026cPaR4rmaxe4hTjpf nXtdt04JmJ1VwpUWqd8fQahVTnQBSCA= X-Google-Smtp-Source: ABdhPJzpWd1V5P40uCJfcqTW4HR913yZ2uBSsR1T4sak6eWxZpbYyaxd0BtG8703N9ycOjbH/TIhVA== X-Received: by 2002:a62:7a09:0:b029:1f1:5cf4:3fd7 with SMTP id v9-20020a627a090000b02901f15cf43fd7mr24902877pfc.66.1617666696616; Mon, 05 Apr 2021 16:51:36 -0700 (PDT) Original-Received: from [192.168.2.128] (64-52-176-132.championbroadband.com. [64.52.176.132]) by smtp.gmail.com with ESMTPSA id r10sm17501108pfq.216.2021.04.05.16.51.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Apr 2021 16:51:36 -0700 (PDT) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=matt.wette@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 autolearn=ham autolearn_force=no X-Spam_action: no action 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:17400 Archived-At: When scripts with load-extension are compiled, the compiler does not know what symbols are defined in the extension so you may get warnings. Are you getting an error or just the warning? On 4/5/21 10:44 AM, Paul Emsley wrote: > Hi Linas, > > Thanks for your reply. > > Let me clarify if I can. I have many C++ functions that I would like to use from scheme. I am using > SWIG to generate wrappers for these functions, and these get added > at the "root module" > > http://www.swig.org/Doc3.0/Guile.html > > The default linkage is the simplest; nothing special is done. In this case > the function SWIG_init() is exported. Simple linkage can be used in several ways: > > Embedded Guile, no modules. You want to embed a Guile interpreter into your > program; all bindings made by SWIG shall show up in the root module. Then call > SWIG_init() in the inner_main() function > > So that is what I was trying to do. My understanding was that enhanced-ligand-coot-p > and its friends would be added so that their usage would be no different to list, string?, > map and any number of basic scheme functions. However something is amiss. > > If I try this: > ./coot > Enter `,help' for help. > scheme@(guile-user)> (load "test-embedding.scm") > (55555555555555 #f) > > Now, if I install that in $prefix/share/guile/site > If I try this: > ./coot > Enter `,help' for help. > scheme@(guile-user)> (use-modules (test-embedding)) > While compiling expression: > In procedure module-lookup: Unbound variable: enhanced-ligand-coot-p > scheme@(guile-user)> > > Is that because the "compiler" doesn't know where enhanced-ligand-coot-p is? Maybe the compiler > is not my application, so that's why it's not there? > > If that is the case, then can I not compile my .scm files? How to do that? Or can I somehow say > "don't worry that it's not there now, when the application runs, it will be there"? > > Thanks, > > Paul. > > p.s. It's quite likely that Coot was used in the analysis of spike proteins from coronavirus > that lead to 2P and hexapro stabilization mutants, and they have been taken up by the pharmaceutical > companies and embedded into the mRNA or more conventional preps. So you can have some guile-1.8.8-based > technology squirted into your arm next week. > > > On Mon, 2021-04-05 at 10:27 -0500, Linas Vepstas wrote: >> Hi Paul, >> >> Conventionally, a guile module would look something like >> >> >> (define-module (test-embedding)) >> (use-modules (srfi srfi-1)) ; .. etc >> >> (define (enhanced-ligand-coot-p) #t) ; etc. >> >> (export enhanced-ligand-coot-p) >> >> >> In your example, you never explained how "enhanced-ligand-coot-p" >> magically showed up in your environment. >> >> When a module is defined, it starts with a new environment. The module >> cannot access stuff you've defined previously; you would have to import >> it somehow. >> >> --linas >> >> >> On Mon, 2021-04-05 at 11:24 +0100, Paul Emsley wrote: >>> Hi, >>> >>> I am trying to bring my swigged Gtk2 + guile 1.8.8 + guile-gtk >>> application up to date and I'd like some help please. >>> >>> My SWIG usage wraps many function, including >>> enhanced_coot_ligand_p(). I am confused between the difference >>> between >>> functions that are available from C/C++ and those from a scheme >>> script: >>> >>> if my inner_main looks like this: >>> >>> void inner_main(void *closure, int argc, char **argv) { >>> >>> SWIG_init(); >>> std::string handler_string = "(lambda (key . args) "; >>> handler_string += "(display (list \"Error in proc:\" key \" args: >>> \" args)) (newline))"; >>> SCM handler = scm_c_eval_string(handler_string.c_str()); >>> std::string thunk_str = "(lambda() (display (list >>> 444444444444444444 (enhanced-ligand-coot-p))) (newline))\n"; >>> SCM thunk = scm_c_eval_string(thunk_str.c_str()); >>> scm_catch(SCM_BOOL_T, thunk, handler); >>> gtk_main(); >>> >>> } >>> >>> then I get on the terminal what I expected: >>> >>> (444444444444444444 #f) >>> >>> (i.e. enhanced-ligand-coot-p is evaluated) >>> >>> >>> if my inner_main looks like this: >>> void inner_main(void *closure, int argc, char **argv) { >>> >>> SWIG_init(); >>> std::string handler_string = "(lambda (key . args) "; >>> handler_string += "(display (list \"Error in proc:\" key \" args: >>> \" args)) (newline))"; >>> SCM handler = scm_c_eval_string(handler_string.c_str()); >>> std::string thunk_str = "(use-modules (test- >>> embedding))\n"; //////////// different /////////////// >>> SCM thunk = scm_c_eval_string(thunk_str.c_str()); >>> scm_catch(SCM_BOOL_T, thunk, handler); >>> gtk_main(); >>> >>> } >>> >>> then I get: >>> >>> ;; compiling /home/paule/autobuild/Linux-pen-pre-release- >>> gtk3/share/guile/site/test-embedding.scm >>> ;;; test-embedding.scm:21:30: warning: possibly unbound variable >>> `enhanced-ligand-coot-p' >>> ;;; compiled /home/paule/.cache/guile/ccache/2.2-LE-8- >>> 3.A/home/paule/autobuild/Linux-pen-pre-release- >>> gtk3/share/guile/site/test-embedding.scm.go >>> ------------------- test embedding! ----------------------- >>> Backtrace: >>> 18 (apply-smob/1 #) >>> In ice-9/boot-9.scm: >>> 2312:4 17 (save-module-excursion _) >>> In ice-9/eval-string.scm: >>> 38:6 16 (read-and-eval # #:lang _) >>> In ice-9/eval.scm: >>> 721:20 15 (primitive-eval _) >>> In ice-9/psyntax.scm: >>> 1262:36 14 (expand-top-sequence _ _ _ #f _ _ _) >>> 1209:24 13 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) >>> …) >>> 285:10 12 (parse _ (("placeholder" placeholder)) (()) _ c&e (eval) >>> …) >>> In ice-9/boot-9.scm: >>> 3377:20 11 (process-use-modules _) >>> 222:17 10 (map1 (((test-embedding)))) >>> 3378:31 9 (_ ((test-embedding))) >>> 2800:17 8 (resolve-interface (test-embedding) #:select _ #:hide _ >>> …) >>> In ice-9/threads.scm: >>> 390:8 7 (_ _) >>> In ice-9/boot-9.scm: >>> 2726:13 6 (_) >>> In ice-9/threads.scm: >>> 390:8 5 (_ _) >>> In ice-9/boot-9.scm: >>> 2994:20 4 (_) >>> 2312:4 3 (save-module-excursion _) >>> 3014:26 2 (_) >>> In unknown file: >>> 1 (primitive-load-path "test-embedding" #>> 7f98d…>) >>> In test-embedding.scm: >>> 19:0 0 (_) >>> >>> test-embedding.scm:4:0: In procedure module-lookup: Unbound variable: >>> enhanced-ligand-coot-p >>> >>> >>> >>> test-embedding.scm looks like this and is installed in >>> $prfx/share/guile/site >>> >>> (display "------------- test embedding! ------------\n") >>> (display (list 55555555555555 (enhanced-ligand-coot-p))) >>> (newline) >>> >>> >>> So, inner_main() knows that enhanced-ligand-coot-p is available, but >>> the scheme script does not. I don't know how to >>> resolve this. >>> >>> How do I get a list of the available functions? >>> >>> Thanks in advance for your help. >>> >>> Paul. >>> >>> >>> >