I've been working on building a DSL in Racket (as a #lang collection), and have 
reached the stage where it's functioning as expected and ready to be embedded 
in my application (which is written in C++).

I have modified the `run` function from the embedding example here 
(https://docs.racket-lang.org/inside/embedding.html) as follows:

|static int run(Scheme_Env *e, int argc, char *argv[]) {
|       Scheme_Object *curout;
|       int i;
|       Scheme_Thread *th;
|       
|       mz_jmp_buf * volatile save, fresh;
|       
|       /* Declare embedded modules in "base.hpp": */
|       declare_modules(e);
|       /*** Alternatively (see email commentary below):
|       scheme_set_collects_path(scheme_make_path(argv[1]));
|       scheme_init_collection_paths(e, scheme_null);
|        */
|       curout = scheme_get_param(scheme_current_config(),
|                                                         MZCONFIG_OUTPUT_PORT);
|       
|       th = scheme_get_current_thread();
|       for (i = 2; i < argc; i++) {
|               save = th->error_buf;
|               th->error_buf = &fresh;
|               
|               if (scheme_setjmp(*th->error_buf)) {
|                       th->error_buf = save;
|                       return -1; /* There was an error */
|               } else {
|                       Scheme_Object *v, *a[2];
|                       v = scheme_load(argv[i]);
|                       scheme_display(v, curout);
|                       scheme_display(scheme_make_char('\n'), curout);
|                       th->error_buf = save;
|               }
|       }
|       
|       return 0;
|}


When I run my program, so that the file to be executed is in `argv[2]`, I get 
an error message that begins as follows:

|../libraries/dsl-exec/racket-src/gpsm-test.gpsm:1:0: #%top-interaction: 
unbound identifier;
| also, no #%app syntax transformer is bound
|  at: #%top-interaction

Note that when I run programs written in my DSL with a standalone interpreter, 
this error does not appear, and I *explicitly* export `#%top-interaction`, 
`#%app`, `#%module-begin`, and `#%datum`.

I noticed some oddities when using `raco ctool`. For example, the documentation 
claims that a module specified for embedding with ++lib will embed all of its 
dependencies, but my #lang's reader submodule needed to be explicitly specified 
with its own ++lib argument. To see if this was a contributing factor, I also 
tried using a manual `scheme_set_collects_path` and 
`scheme_init_collections_paths` combo (with `argv[1]` pointing to the location 
of my collects dir on disk), but got the same error as with the embedded 
versions of the modules.

As a follow-up, using the manually-specified collections path variant of the 
code above, I also tried to execute the following simple Racket program (to 
isolate if the use of my #lang specifically was a contributing factor):
|#lang racket
|
|(display (+ 5 6))
|(newline)

The same error as before was immediately raised:
|racket-test.rkt:1:0: #%top-interaction: unbound identifier;
| also, no #%app syntax transformer is bound
|  at: #%top-interaction


I assume I'm missing some crucial piece of the embedded Racket puzzle, but I 
have no idea what it is.

(I might also recommend that whatever this missing piece is be *clearly* 
documented in future editions of the documentation, since it seems like a 
fairly basic use-case).

Thanks,
~Thomas

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to