Best way to integrate "schemesh" written in Chez Scheme, into Racket ecosystem?

This sounds very exciting! I have a few off-hand thoughts.

This is definitely an option you could use for all or part of the code. You can use the ffi/unsafe/vm library to access Chez Scheme functionality from Racket: there’s more discussion here on how to load additional Chez Scheme libraries.

However, as the name of ffi/unsafe/vm implies, Chez Scheme functionality corresponds to the “unsafe” layer of Racket. There are some documented caveats, particularly about potential uses of dynamic-wind and Racket procedures that may not be Chez Scheme procedures.

I think it would probably work out better to write a compatibility layer in Racket that would let most of your code be shared between both implementations.

To the extent you need them, ffi/unsafe/vm is probably the best way to get these. You could also consider the unix-signals package.

However, with respect to blocking C functions, note that Racket’s IO functions are non-blocking at the level of the OS process (though some block at the level of the green Racket thread). You might want to use Racket’s process control functionality instead of going through C. In particular, some variants can handle bridging the Racket-thread-specific current-directory parameter and wiring up arbitrary Racket ports to stdin/out/err.

Racket’s reader is highly extensible: you can add dispatch and delimiter macros to the readtable to cover #!shell, {, }, and everything else. Extending the Racket reader can also help you cooperate with syntax coloring and REPL support that works with both DrRacket and Racket’s command-line expeditor (and maybe racket-mode in Emacs, and/or other editors via the LSP?).

The needed functionality definitely exists, and may be as simple as calling (read-eval-print-loop) after setting up an appropriate namespace and such. If you need finer-grained control, all of the pieces are also provided.

There are ways to do conditional compilation and reflection in Racket, though you may need less of it: Racket always has flvectors, for example.

The Racket FFI is a layer on top of the Chez Scheme FFI, and vectors, bytevectors (a.k.a. byte strings), and lists are the same in Racket as in Chez Scheme (except IIRC for impersonated vectors, including chaperones), so all of this should work. In particular, a byte string is a Racket cpointer?. This might be an area where ffi/unsafe/vm would be useful.

If my suggestions above work out, the autocompletion in expeditor should do this for you. If you end up needing to reimplement more functionality, all the reflective operations you need exist, e.g. namespace-mapped-symbols.

We’ve got it: generate-temporaries

(Also, this one is standardized in (rnrs syntax-case).)

1 Like