[plt-scheme] embedding & modules problem
Dave Griffiths wrote:
> Hi all,
>
> I'm trying to understand how modules work when created inside an
> embedding application. If I run the adapted 3m example below with:
>
> "(require my-module) (my-func)"
>
> It fails with:
>
> #f::9: my-module: standard-module-name-resolver: collection not found:
> "my-module" in any of: () in: my-module
>
> Even though the module is defined in the current environment...
It seems like you should be using this require form instead:
(require 'my-module)
Does that help?
Ryan
>
> cheers,
>
> dave
>
> ---->8----
>
> #include "scheme.h"
>
> #include "base.c"
>
> Scheme_Object *my_func(int argc, Scheme_Object **argv)
> {
> return scheme_void;
> }
>
> static int run(Scheme_Env *e, int argc, char *argv[])
> {
> Scheme_Object *curout = NULL, *v = NULL, *a[2] = {NULL, NULL};
> Scheme_Env *menv = NULL;
> Scheme_Config *config = NULL;
> int i;
> mz_jmp_buf * volatile save = NULL, fresh;
>
> MZ_GC_DECL_REG(9);
> MZ_GC_VAR_IN_REG(0, e);
> MZ_GC_VAR_IN_REG(1, curout);
> MZ_GC_VAR_IN_REG(2, save);
> MZ_GC_VAR_IN_REG(3, config);
> MZ_GC_VAR_IN_REG(4, v);
> MZ_GC_VAR_IN_REG(5, menv);
> MZ_GC_ARRAY_VAR_IN_REG(6, a, 2);
> MZ_GC_REG();
>
> declare_modules(e);
>
> v = scheme_intern_symbol("scheme/base");
> scheme_namespace_require(v);
>
> // make a module
> menv=scheme_primitive_module(scheme_intern_symbol("my-module"), e);
> scheme_add_global("my-func", scheme_make_prim_w_arity(my_func,
> "my-func", 0, 0), menv);
> scheme_finish_primitive_module(menv);
>
> config = scheme_current_config();
> curout = scheme_get_param(config, MZCONFIG_OUTPUT_PORT);
>
> for (i = 1; i < argc; i++) {
> save = scheme_current_thread->error_buf;
> scheme_current_thread->error_buf = &fresh;
> if (scheme_setjmp(scheme_error_buf)) {
> scheme_current_thread->error_buf = save;
> return -1; /* There was an error */
> } else {
> v = scheme_eval_string(argv[i], e);
> scheme_display(v, curout);
> v = scheme_make_char('\n');
> scheme_display(v, curout);
> /* read-eval-print loop, uses initial Scheme_Env: */
> a[0] = scheme_intern_symbol("scheme/base");
> a[1] = scheme_intern_symbol("read-eval-print-loop");
> v = scheme_dynamic_require(2, a);
> scheme_apply(v, 0, NULL);
> scheme_current_thread->error_buf = save;
> }
> }
>
> MZ_GC_UNREG();
>
> return 0;
> }
>
> int main(int argc, char *argv[])
> {
> return scheme_main_setup(1, run, argc, argv);
> }
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme