* Creating Modules within C @ 2006-11-16 22:48 Volkan YAZICI 2006-11-17 11:34 ` Ludovic Courtès 0 siblings, 1 reply; 5+ messages in thread From: Volkan YAZICI @ 2006-11-16 22:48 UTC (permalink / raw) Hi, Within scm_eval(), I need to use a very simple module: (define-module ultra-complex-thingy #:pure) (Yeah, that's the complete source code of my module.) The problem is, how can I create and use that module within my C code, in scm_eval()? Any assistance will be really appreciated. Regards. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Creating Modules within C 2006-11-16 22:48 Creating Modules within C Volkan YAZICI @ 2006-11-17 11:34 ` Ludovic Courtès 2006-11-20 18:44 ` Volkan YAZICI 0 siblings, 1 reply; 5+ messages in thread From: Ludovic Courtès @ 2006-11-17 11:34 UTC (permalink / raw) Cc: guile-user Hi, Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > Within scm_eval(), I need to use a very simple module: > > (define-module ultra-complex-thingy #:pure) > > (Yeah, that's the complete source code of my module.) The problem is, > how can I create and use that module within my C code, in scm_eval()? > Any assistance will be really appreciated. You could write a piece of Scheme to create the relevant module. Namely, you could start with something like this: (let ((m (make-module))) (module-use-interfaces! m (module-public-interface the-root-module))) And then bind that to some variable accessible from C (or pass it to a Scheme procedure written in C that will just store it in a C variable that you can later access). Most of the module system is written in Scheme, which is why using it from C is not always convenient. Also, large parts are undocumented but one should try as much as possible to avoid using them in order to be "future-proof". Thanks, Ludovic. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Creating Modules within C 2006-11-17 11:34 ` Ludovic Courtès @ 2006-11-20 18:44 ` Volkan YAZICI 2006-11-22 17:43 ` Ludovic Courtès 0 siblings, 1 reply; 5+ messages in thread From: Volkan YAZICI @ 2006-11-20 18:44 UTC (permalink / raw) Cc: guile-user Hi, On Nov 17 12:34, Ludovic Courtès wrote: > Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > > Within scm_eval(), I need to use a very simple module: > > > > (define-module ultra-complex-thingy #:pure) > > > > (Yeah, that's the complete source code of my module.) The problem is, > > how can I create and use that module within my C code, in scm_eval()? > > Any assistance will be really appreciated. > > You could write a piece of Scheme to create the relevant module. > Namely, you could start with something like this: > > (let ((m (make-module))) > (module-use-interfaces! m > (module-public-interface the-root-module))) > > And then bind that to some variable accessible from C (or pass it to a > Scheme procedure written in C that will just store it in a C variable > that you can later access). First, thanks so much for your answer. But I couldn't find any documentation about the above make-module, module-use-interfaces! and module-use-interfaces functions used. I looked at the source code but, because of I'm totally green about module related stuff, couldn't figure out anything significant. I don't want to be lazy but... Can you please explain a bit more about the above usage of modules? For instance, you said, I can bind that [thing] to some variable in C. But then how will I use it? [I'm not sure if this will be a useful information, but anyway:] I just want to execute my individual procedures in a #:pure'ified environment in PL/scheme. That's all. I hope I'm on the right direction. Regards. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Creating Modules within C 2006-11-20 18:44 ` Volkan YAZICI @ 2006-11-22 17:43 ` Ludovic Courtès 2006-11-22 21:08 ` Volkan YAZICI 0 siblings, 1 reply; 5+ messages in thread From: Ludovic Courtès @ 2006-11-22 17:43 UTC (permalink / raw) Cc: guile-user Hi, Volkan YAZICI <yazicivo@ttnet.net.tr> writes: > Hi, > > On Nov 17 12:34, Ludovic Courtès wrote: >> You could write a piece of Scheme to create the relevant module. >> Namely, you could start with something like this: >> >> (let ((m (make-module))) >> (module-use-interfaces! m >> (module-public-interface the-root-module))) >> >> And then bind that to some variable accessible from C (or pass it to a >> Scheme procedure written in C that will just store it in a C variable >> that you can later access). > > First, thanks so much for your answer. But I couldn't find any > documentation about the above make-module, module-use-interfaces! and > module-use-interfaces functions used. I looked at the source code but, > because of I'm totally green about module related stuff, couldn't figure > out anything significant. A "module" object is (roughly) little more than a hash table (where symbols of global variables are looked up) and a list of modules depended on. `make-module' is the constructor of module objects: it creates, a new, empty module, with no dependencies and where no bindings are defined (not even `lambda', `let', etc.) In turn, `module-use-interfaces!' modifies a module (the first argument) in order to have it depend on a number of modules (the second and following arguments). The term "interface" refers to what a module exposes for use by other modules, i.e., what it exports (more precisely, this is the "public" interface). And finally, `the-root-module' is, well, the "root" module of Guile, i.e., the one that contains all the bindings that are visible "by default". > I don't want to be lazy but... Can you please explain a bit more about > the above usage of modules? For instance, you said, I can bind that > [thing] to some variable in C. But then how will I use it? Say you have C variable "my_module" bound to a module created as explained above. Then, you can evaluate expression in the context of that module as follows: SCM result, expr; expr = scm_list_3 (scm_from_locale_symbol ("+"), scm_from_int (2), scm_from_int (2)); result = scm_eval (expr, my_module); This is maybe a bit terse but I hope it helps. Thanks, Ludovic. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Creating Modules within C 2006-11-22 17:43 ` Ludovic Courtès @ 2006-11-22 21:08 ` Volkan YAZICI 0 siblings, 0 replies; 5+ messages in thread From: Volkan YAZICI @ 2006-11-22 21:08 UTC (permalink / raw) Cc: guile-user Hi, On Nov 22 06:43, Ludovic Courtès wrote: > A "module" object is (roughly) little more than a hash table (where > symbols of global variables are looked up) and a list of modules > depended on. > > `make-module' is the constructor of module objects: it creates, a new, > empty module, with no dependencies and where no bindings are defined > (not even `lambda', `let', etc.) In turn, `module-use-interfaces!' > modifies a module (the first argument) in order to have it depend on a > number of modules (the second and following arguments). > > The term "interface" refers to what a module exposes for use by other > modules, i.e., what it exports (more precisely, this is the "public" > interface). Yeah, I figured those out from ice-9/boot-9.scm and modules.c too. > And finally, `the-root-module' is, well, the "root" module of Guile, > i.e., the one that contains all the bindings that are visible "by > default". > > > I don't want to be lazy but... Can you please explain a bit more about > > the above usage of modules? For instance, you said, I can bind that > > [thing] to some variable in C. But then how will I use it? > > Say you have C variable "my_module" bound to a module created as > explained above. Then, you can evaluate expression in the context of > that module as follows: > > SCM result, expr; > > expr = scm_list_3 (scm_from_locale_symbol ("+"), > scm_from_int (2), scm_from_int (2)); > result = scm_eval (expr, my_module); > > This is maybe a bit terse but I hope it helps. Thanks so much for your kindly help. They all really helped. (As a proof, see CVS commits of the PL/scheme project. ;-) Regards. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-11-22 21:08 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-11-16 22:48 Creating Modules within C Volkan YAZICI 2006-11-17 11:34 ` Ludovic Courtès 2006-11-20 18:44 ` Volkan YAZICI 2006-11-22 17:43 ` Ludovic Courtès 2006-11-22 21:08 ` Volkan YAZICI
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).