Interactive Evaluation in Slideshow
repl-area
make-repl-group
repl-group?
result-area
make-module-backing
module-backing?
module-area
module-backing-module-name
6.12

Interactive Evaluation in Slideshow

The slideshow/repl module provides support for picts (using interactive) that allow interactive evaluation within a slide presentation.

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?
Creates a pict that displays as an interactive evaluation (i.e., a read-eval-print loop). Each such pict has its own evaluation context whose display is reset when the slide enclosing the pict is displayed.

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
Returns an evaluation context to be shared by multiple module areas (created with module-area, each with a backing from make-module-backing) and result areas (created with result-area).

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
Returns #t if v is a context created by make-repl-group, #f otherwise.

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?
Like repl-area, but for the result area (analogous to DrRacket’s interactions window) for a context created by make-repl-group.

Multiple result areas created for a group display the same interaction content.

procedure

(make-module-backing group 
  [#:module-name module-name 
  #:change-callback change-callback] 
  content-line ...) 
  module-backing?
  group : repl-group?
  module-name : path-string? = "program.rkt"
  change-callback : ((is-a?/c text%) . -> . any) = void
  content-line : string?
Creates a module representing module-name in the context represented by group. Each such module backing should have a distinct module-name. The module content is initialized by the content-line strings.

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.

The optional change-callback function is called whenever the text content of the module is changed by the user. The editor for the module’s content is provided to change-callback.

Changed in version 1.3 of package slideshow-repl: Added change-callback.

procedure

(module-backing? v)  boolean?

  v : any/c
Returns #t if v is a context created by make-module-backing, #f otherwise.

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
Similar to repl-area, but for the content (analogous to DrRacket’s definitions window) of a particular module created by make-module-backing within a context created by make-repl-group.

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?
Reports the module name of a module backing (as provided to make-module-backing).