Interactive Evaluation in Slideshow
(require slideshow/repl) | package: slideshow-repl |
The following example shows how to set up two modules displayed in their own picts along with a result area:
(define rg (make-repl-group)) ; the first module (define backing-1 (make-module-backing rg #:module-name "fact.rkt" "#lang racket" "(define (fact n)" " (if (= n 0) 1 (* n (fact (sub1 n)))))" "(provide fact)")) ; the second module (define backing-2 (make-module-backing rg "#lang racket" "(require \"fact.rkt\")" "(fact 5)")) ; shows content of module 1 (module-area backing-1) ; shows content of module 2 (module-area backing-2) ; shows the result of running either module (use F5) (result-area rg)
procedure
(repl-area [ #:width width #:height height #:font-size font-size #:own-size? own-size? #:background background #:prompt prompt-str #:make-namespace make-namespace] content ...) → pict? width : real? = (* client-w 2/3) height : real? = (* client-h 1/4) font-size : (or/c #f (integer-in 1 1024)) = #f own-size? : boolean? = #f background : (or/c #f (is-a?/c color%) string?) = #f prompt-str : string? = "> " make-namespace : (-> namespace?) = make-base-namespace content : string?
The width and height arguments determine the size of the resulting pict.
If font-size is not #f, then it determines a font size used. If own-size? is true, then the size applies only to the font for this pict. All slideshow/repl-based picts with own-size? as #f, however, use the same font size when they appear on the same slide (so all such picts should specify a consistent size, or else an unspecified pict’s size is used).
When background is not #f, it determines a background for the area.
The prompt-str determines a prompt that is show for input expressions in the interactive-evaluation area.
The make-namespace argument determines the namespace (created once) for evaluation.
The content strings, if any, are inserted into the evaluation area after the prompt, with a newline between each content string.
Changed in version 1.2 of package slideshow-repl: Added own-size?.
procedure
(make-repl-group [ #:log-file log-file #:prompt prompt-str #:make-namespace make-namespace]) → repl-group? log-file : path-string? = "eval-log.rktl" prompt-str : (or/c #f string?) = #f make-namespace : (-> namespace?) = make-base-namespace
When a module area’s content is evaluated, the content of the module is recorded to log-file.
The prompt-str argument determines the prompt that is shown in an result area. If it is not #f, then he result area supports interactive evaluation in the same way as repl-area.
The make-namespace argument determines the namespace for evaluation. A fresh namespace is created using make-namespace on each evaluation triggered for a module in the group.
procedure
(repl-group? v) → boolean?
v : any/c
procedure
(result-area group [ #:width width #:height height #:background background #:font-size font-size #:own-size? own-size?] content ...) → pict? group : repl-group? width : real? = (* client-w 2/3) height : real? = (* client-h 1/4) background : (or/c (is-a?/c color%) string?) = "white" font-size : (or/c #f (integer-in 1 1024)) = #f own-size? : boolean? = #f content : string?
Multiple result areas created for a group display the same interaction content.
procedure
(make-module-backing group [ #:module-name module-name] content-line ...) → module-backing? group : repl-group? module-name : path-string? = "program.rkt" content-line : string?
When the module is evaluated, a require of each can use one of the other modules in the group by using the other’s module’s module-name.
Multiple modules areas created with module-area can share a backing, so that they provide the same view on the underlying content. For example, a narrow view on one slide might be replaced by a wider view on another side with the same module backing, so that edits via the first are preserved in the second area’s display.
procedure
(module-backing? v) → boolean?
v : any/c
procedure
(module-area backing [ #:width width #:height height #:background background #:font-size font-size #:own-size? own-size? #:auto-eval? auto-eval?]) → pict? backing : module-backing? width : real? = (* client-w 1/4) height : real? = (* client-h 1/4) background : (or/c (is-a?/c color%) string?) = "white" font-size : (or/c #f (integer-in 1 1024)) = #f own-size? : boolean? = #f auto-eval? : any/c = #f
When the keyboard focus in the area, typing F5 requires the module. Typing F6 requires the module’s test submodule.
procedure
(module-backing-module-name backing) → path-string?
backing : module-backing?