I recently tried to update my "racket eval bot", which uses racket/sandbox
to evaluate racket (and typed/racket) code, to support Rhombus. But I failed, neither make-evaluator
nor make-module-evaluator
works.
> ((make-evaluator 'rhombus) "1+2")
program: #%module-begin: expected more terms
at:
within: (#%module-begin)
in: (#%module-begin)
[,bt for context]
>
> ((make-module-evaluator "#lang rhombus") "1+2")
#%top-interaction: bad syntax
in: (#%top-interaction . 1+2)
[,bt for context]
I think the cause is the following code from racket/sandbox
, which uses read-syntax
from (#lang) racket. It means only s-exp code is support (natively) by racket/sandbox
. Although using parse-all
from shrubbery with #:mode 'interactive
is a possible solution, I want a more gerenal way to evaluate non-sexp code, such as #lang datalog, with racket/sandbox
.
After reading some code of DrRacket and racket-mode and partial understanding how their REPLs work, I attempted to dynamic-require
the configure-runtime
submodule in the evaluator, to update current-read-interaction
and access its value. But I also failed.
Is it possible to let racket/sandbox
to support non-sexp code in general?
And I noticed scribble/rhombus
, which also uses racket/sandbox
(through scribble/example
) to evaluate rhombus code. However, it first reads (or parses) the code into s-exps, and then "applies" examples
with these s-exps. How can we continue to support this usage if the answer to the former question is yes, in other words, how can we support both the raw representation of one non-sexp #lang and the parsed s-exp representation of it in racket/sandbox
?