unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Linas Vepstas <linas@linas.org>
To: Paul Emsley <pemsley@mrc-lmb.cam.ac.uk>,
	Guile User Mailing List <guile-user@gnu.org>
Subject: Re: Guile + SWIG
Date: Mon, 05 Apr 2021 10:27:12 -0500	[thread overview]
Message-ID: <2a6711742cea0cf53342f70a2941b26e48efd864.camel@linas.org> (raw)
In-Reply-To: <65bb42ce8d587b284b70d48f2f4b0c99e5c37cf7.camel@mrc-lmb.cam.ac.uk>

Hi Paul,

Conventionally, a guile module would look something like


 (define-module (test-embedding))
 (use-modules (srfi srfi-1)) ; .. etc

 (define (enahanced-ligand-coot-p) #t) ; etc.

 (export enahanced-ligand-coot-p)


In your example, you never explained how "enahanced-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 #<catch-closure 7f98d1436b20>)
> In ice-9/boot-9.scm:
>    2312:4 17 (save-module-excursion _)
> In ice-9/eval-string.scm:
>      38:6 16 (read-and-eval #<input: string 7f98d08acbd0> #: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" #<procedure
> 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.
> 
> 
> 




  parent reply	other threads:[~2021-04-05 15:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05 10:24 Guile + SWIG Paul Emsley
2021-04-05 14:44 ` Linas Vepstas
2021-04-05 15:27 ` Linas Vepstas [this message]
2021-04-05 17:44   ` Paul Emsley
2021-04-05 23:51     ` Matt Wette
2021-04-08  7:13       ` Paul Emsley
2021-04-08 21:11         ` David Pirotte
  -- strict thread matches above, loose matches on Subject: below --
2021-04-05  9:39 Paul Emsley

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=2a6711742cea0cf53342f70a2941b26e48efd864.camel@linas.org \
    --to=linas@linas.org \
    --cc=guile-user@gnu.org \
    --cc=pemsley@mrc-lmb.cam.ac.uk \
    /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).