[racket] Problems using Sandbox and Scribble

From: Lucas Paul (reilithion at gmail.com)
Date: Wed Jan 28 12:56:38 EST 2015

Thanks for that, Matthew. Unfortunately, when I try that, I get a new error:

namespace-attach-module: a different instance of the same module is
already in the destination namespace
  module name: "/usr/share/racket/collects/racket/stxparam-exptime.rkt"

On Tue, Jan 27, 2015 at 2:03 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> The `#:requires` option of `make-evaluator` requires the named modules
> in the sandbox's namespace, but the module instances are distinct from
> any instances in the original namespace.
>
> To attach the original namespace's instances to the sandbox's
> namespace, use the `sandbox-namespace-specs` parameter:
>
>  (define safe-eval
>    (parameterize ([sandbox-namespace-specs
>                    (append (sandbox-namespace-specs)
>                            '(scribble/manual scribble/racket))])
>      (make-evaluator 'racket/base
>                      #:requires '(scribble/manual scribble/racket))))
>
> At Tue, 27 Jan 2015 13:22:01 -0700, Lucas Paul wrote:
>> Hi.
>>
>> I want to evaluate some scribble things (in a sandbox) and then
>> combine them with other scribble things I already have lying around.
>> But I'm running into a problem.
>>
>> If I, for example, make a nicely formatted (racket) code block in a
>> sandbox, and then put it in a (para) outside of that sandbox, the
>> world explodes. Here is a minimal example:
>>
>> #lang racket
>>
>> (require racket/sandbox
>>          scribble/manual)
>>
>> (define safe-eval
>>   (make-evaluator 'racket/base #:requires '(scribble/manual scribble/racket)))
>>
>> (pretty-print (racket foo))  ; Gives one output
>> (pretty-print (safe-eval '(racket foo)))  ; Gives a slightly DIFFERENT output
>>
>> (para (racket foo))  ; Finishes happily
>> (para (safe-eval '(racket foo)))  ; Error
>>
>> ; end
>>
>> This is the error I get:
>>
>> para: contract violation
>>   expected: pre-content?
>>   given: (cached-element (style "RktSym" (list 'tt-chars (css-addition
>> '(collects #"scribble" #"racket.css")) (tex-addition '(collects
>> #"scribble" #"racket.tex")))) "foo" (vector (style "RktSym" (list
>> 'tt-chars (css-addition '(collects #"scribble" #"racket...
>>   in: an element of
>>       the rest argument of
>>       (->*
>>        ()
>>        (#:style (or/c style? string? symbol? #f))
>>        #:rest
>>        (listof pre-content?)
>>        paragraph?)
>>   contract from:
>>       <pkgs>/scribble-lib/scribble/base.rkt
>>   blaming: anonymous-module
>>    (assuming the contract is correct)
>>   at: <pkgs>/scribble-lib/scribble/base.rkt:337.2
>>
>> What is going on? Why does the same piece of code have two different
>> results depending on where it's executing? And most importantly, is
>> there a way for me to get this to work the way I /want/?
>>
>> - Lucas Paul
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users

Posted on the users mailing list.