unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guile + SWIG
@ 2021-04-05 10:24 Paul Emsley
  2021-04-05 14:44 ` Linas Vepstas
  2021-04-05 15:27 ` Linas Vepstas
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Emsley @ 2021-04-05 10:24 UTC (permalink / raw)
  To: Guile User Mailing List

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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-05 10:24 Guile + SWIG Paul Emsley
@ 2021-04-05 14:44 ` Linas Vepstas
  2021-04-05 15:27 ` Linas Vepstas
  1 sibling, 0 replies; 8+ messages in thread
From: Linas Vepstas @ 2021-04-05 14:44 UTC (permalink / raw)
  To: Paul Emsley, Guile User Mailing List

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.
> 
> 
> 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-05 10:24 Guile + SWIG Paul Emsley
  2021-04-05 14:44 ` Linas Vepstas
@ 2021-04-05 15:27 ` Linas Vepstas
  2021-04-05 17:44   ` Paul Emsley
  1 sibling, 1 reply; 8+ messages in thread
From: Linas Vepstas @ 2021-04-05 15:27 UTC (permalink / raw)
  To: Paul Emsley, Guile User Mailing List

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.
> 
> 
> 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-05 15:27 ` Linas Vepstas
@ 2021-04-05 17:44   ` Paul Emsley
  2021-04-05 23:51     ` Matt Wette
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Emsley @ 2021-04-05 17:44 UTC (permalink / raw)
  To: Linas Vepstas, Guile User Mailing List

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 #<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.
> > 
> > 
> > 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-05 17:44   ` Paul Emsley
@ 2021-04-05 23:51     ` Matt Wette
  2021-04-08  7:13       ` Paul Emsley
  0 siblings, 1 reply; 8+ messages in thread
From: Matt Wette @ 2021-04-05 23:51 UTC (permalink / raw)
  To: guile-user

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 #<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.
>>>
>>>
>>>
>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-05 23:51     ` Matt Wette
@ 2021-04-08  7:13       ` Paul Emsley
  2021-04-08 21:11         ` David Pirotte
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Emsley @ 2021-04-08  7:13 UTC (permalink / raw)
  To: guile-user

Hi Matt and Linas,

Thanks for your feedback.

I was indeed confused by thinking the warning was a terminal error, because I also neglected to add a newline
after using display (so it seemed to me as if it was hanging (after years of using python, I expected the 
prompt to be shown on pressing "Return", so when it didn't, I thought that there was something wrong)).

So guile 2.2 is in the bag - and I'm pleased about that. Soon I will be looking at converting guile-gtk scripts to
guile-gnome.

Regards,

Paul.


On Mon, 2021-04-05 at 16:51 -0700, Matt Wette wrote:
> 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 #<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.
> > > > 
> > > > 
> > > > 
> 
> 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guile + SWIG
  2021-04-08  7:13       ` Paul Emsley
@ 2021-04-08 21:11         ` David Pirotte
  0 siblings, 0 replies; 8+ messages in thread
From: David Pirotte @ 2021-04-08 21:11 UTC (permalink / raw)
  To: Paul Emsley; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

Hello Paul,

> So guile 2.2 is in the bag - and I'm pleased about that. Soon I will
> be looking at converting guile-gtk scripts to guile-gnome.

Consider using guile-gi or g-golf instead, guile-gnome is
unmaintained.

If you are interested to chat about this and ask others, join us on
#guile (freenode), both the guile-gi author (Mike Grant) and myself are
there, and though not many yet, we have a few users 'each side', who
might be able to help as well ...

David

Guile-GI
	https://github.com/spk121/guile-gi

G-Golf
	https://www.gnu.org/software/g-golf

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Guile + SWIG
@ 2021-04-05  9:39 Paul Emsley
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Emsley @ 2021-04-05  9:39 UTC (permalink / raw)
  To: Guile User Mailing List

Hi,

I am bringing 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.






^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-08 21:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05 10:24 Guile + SWIG Paul Emsley
2021-04-05 14:44 ` Linas Vepstas
2021-04-05 15:27 ` Linas Vepstas
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

unofficial mirror of guile-user@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-user/0 guile-user/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-user guile-user/ https://yhetil.org/guile-user \
		guile-user@gnu.org
	public-inbox-index guile-user

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.user
	nntp://news.gmane.io/gmane.lisp.guile.user


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git