[racket-dev] question on scribble/eval's do-plain-eval on bytes and strings

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Mar 29 11:25:37 EDT 2012

Hi everyone,

I'm running into some unexpected behavior with regards to how
scribble/eval drives an evaluator in an @interaction.  When I do
something like this:

    @interaction[#:eval my-eval
                       "foobar"]

I see that my-eval is being fed an s-expression of the form:

     `(begin "foobar")

However, my-eval uses a language that does not provide a begin-like
form, so this raises an error.

I've traced the source of this "begin" down to the do-plain-eval
function in scribble/eval.rkt.

             ;; within do-plain-eval:
             (cond [(syntax? s)
                    (syntax-case s (module)
                      [(module . _rest) (syntax->datum s)]
                      [_else s])]
                   [(bytes? s) `(begin ,s)]
                   [(string? s) `(begin ,s)]
                   [else s]))))

I assume it's trying to make sure than an evaluator defined by
racket/sandbox doesn't treat it as program source rather than as data,
since the sandbox treats strings and bytes in a special way.

Would it be equivalent behavior to turn the datum into a syntax object
instead?  That is:

             ;; within do-plain-eval:
             (cond [(syntax? s)
                    (syntax-case s (module)
                      [(module . _rest) (syntax->datum s)]
                      [_else s])]
                   [(bytes? s) (datum->syntax #f s)]
                   [(string? s) (datum->syntax #f s)]
                   [else s]))))

If this looks right, I can send as a patch.

Posted on the dev mailing list.