4.5 Evaluation and Examples
syntax
(interaction maybe-eval maybe-escape datum ...)
maybe-eval =
| #:eval eval-expr maybe-escape =
| #:escape escape-id
The eval-expr must produce a sandbox evaluator via make-evaluator or make-module-evaluator with the sandbox-output and sandbox-error-output parameters set to 'string. If eval-expr is not provided, an evaluator is created using make-base-eval. See also make-eval-factory.
If the value of current-print in the sandbox is changed from its default value, or if print-as-expression in the sandbox is set to #f, then each evaluation result is formatted to a port by applying (current-print) to the value; the output port is set to a pipe that supports specials in the sense of write-special, and non-character values written to the port are used as content. Otherwise, when the default current-print is in place, result values are typeset using to-element/no-color.
Certain patterns in datum are treated specially:
A datum of the form (code:line code-datum (code:comment comment-datum ...)) is treated as code-datum for evaluation.
Other uses of code:comment and code:blank are stripped from each datum before evaluation.
A datum of the form (eval:alts show-datum eval-datum) is treated as show-datum for typesetting and eval-datum for evaluation.
A datum of the form (eval:check eval-datum expect-datum) is treated like eval-datum, but check-datum is also evaluated, and an error is raised if they are not equal?.
A datum of the form (eval:result content-expr out-expr err-expr) involves no sandboxed evaluation; instead, the content result of content-expr is used as the typeset form of the result, out-expr is treated as output printed by the expression, and err-expr is error output printed by the expression. The out-expr and/or err-expr can be omitted, in which case they default to empty strings.
Normally, eval:result is used in the second part of an eval:alts combination.
A datum of the form (eval:results content-list-expr out-expr err-expr) is treated like an eval:result form, except that content-list-expr should produce a list of content for multiple results of evaluation. As with eval:result, out-expr and err-expr are optional.
As an example,
#lang scribble/manual @(require racket/sandbox scribble/eval) @(define my-evaluator (parameterize ([sandbox-output 'string] [sandbox-error-output 'string]) (make-evaluator 'typed/racket/base))) @interaction[#:eval my-evaluator (: my-sqr (Real -> Real)) (define (my-sqr x) (* x x)) (my-sqr 42)]
uses an evaluator whose language is typed/racket/base.
syntax
(interaction0 maybe-eval maybe-escape datum ...)
syntax
(interaction-eval maybe-eval maybe-escape datum)
syntax
(interaction-eval-show maybe-eval maybe-escape datum)
syntax
(racketblock+eval maybe-eval maybe-escape datum ...)
syntax
(racketblock0+eval maybe-eval maybe-escape datum ...)
syntax
(racketmod+eval maybe-eval maybe-escape name datum ...)
syntax
(def+int maybe-eval maybe-escape defn-datum expr-datum ...)
syntax
(defs+int maybe-eval maybe-escape (defn-datum ...) expr-datum ...)
syntax
(examples maybe-eval maybe-escape datum ...)
syntax
(defexamples maybe-eval maybe-escape datum ...)
procedure
(make-base-eval [#:pretty-print? pretty-print?])
→ (any/c . -> . any) pretty-print? : any/c = #t
If pretty-print? is true, the sandbox’s printer is set to pretty-print-handler.
procedure
(make-base-eval-factory mod-paths [ #:pretty-print? pretty-print?]) → (-> (any/c . -> . any)) mod-paths : (listof module-path?) pretty-print? : any/c = #t
procedure
(make-eval-factory mod-paths [ #:pretty-print? pretty-print?]) → (-> (any/c . -> . any)) mod-paths : (listof module-path?) pretty-print? : any/c = #t
procedure
(close-eval eval) → (one-of/c "")
eval : (any/c . -> . any)
parameter
→ ((any/c . -> . any) any/c boolean? . -> . any) (scribble-eval-handler handler) → void? handler : ((any/c . -> . any) any/c boolean? . -> . any)