[racket] Evaluating pict to string

From: manu d (th3rac25 at gmail.com)
Date: Sun Apr 21 21:26:40 EDT 2013


I am trying to port TryClojure (https://github.com/Raynes/tryclojure), a
web-based REPL, to Racket.

I would like the tutorial part to be based on Racket's 'Quick' tutorial (

To do that, I need to evaluate pict expressions, like (circle 10), to a
string I can return to the browser for rendering.

Right now, I evaluate the strings coming from the browser with the
following code:


(define evaluator
    (parameterize ([sandbox-output 'string]
                          [sandbox-error-output 'string] ...)
      (call-with-limits #f #f
                        (lambda () (make-evaluator 'slideshow)))))

(define (run-code ev str)
  (define res (ev str))
  (define out (get-output ev))
  (define err (get-error-output ev))
  (list res out err))


I know I can convert a pict structure like this: (convert a-pict 'png-bytes)
but (evaluator "(circle 10)") does not evaluate to a pict structure, so I
can't use convert here.

I also cannot see how to use bitmap% save-file method here, because I
cannot get my hands on the bitmap object

Is there a way to parameterize how picts are rendered so I can end up with
a PNG bytestring ?

Thank you

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130422/6d132548/attachment.html>

Posted on the users mailing list.