Racket World: A live Lisp desktop, ported from Schevana

Credit to the authors of Schevana

Before anything else, I want to thank the people whose work makes this chapter possible. Racket World is a simple port to Racket of Schevana, a desktop written in Chez Scheme. Its authors are:

  • Pavel Uvarov (paveluv) wrote Schevana. The idea, the design, the API, the palettes, the styles, the model for the widget kit, and the apps are Pavel’s.
  • Eduardo Cavazos (dharmatech) contributed to Schevana. Its Boids and Springies demos come from Eduardo’s earlier programs, Boids in Niva and Springies in Agave. Behind those are Craig Reynolds’ flocking model (1987) and Douglas DeCarlo’s XSpringies.

The good ideas in this chapter are theirs. Some of the Racket code (styles, palettes, the clock, and icons) translates theirs directly. The rest follows their design, rewritten for Racket. Any bugs belong to the port.

Schevana does much more than this port. It compiles shaders written in Scheme for the GPU, uses SDL3 for windows and input, and calls SDL3, FreeType, and fontconfig through Chez Scheme’s foreign function interface. Racket World uses Racket’s own GUI and drawing libraries and leaves a good deal out. If you like what you see here, please try Schevana, read its source, and star the project. Schevana builds on the work of others too, and lists them in its credits.

Schevana is MIT licensed, copyright (c) 2026 Pavel Uvarov. The port uses the same license. I wrote the port with Claude Code. The files LICENSE and CREDITS.md in the example directory hold the full notices. Please keep them with any copy you make.

Why a live desktop?

Most programs separate the time you write code from the time you run it. You edit a file, stop the program, start it again, and bring it back to the state you were testing.

The Lisp Machines worked another way. The window system, the editor, and the tools were Lisp code in one running system. You could inspect any of it and change it while it ran. Schevana brings that style to a modern computer: its desktop lives inside one window, and you change the desktop from a REPL that runs inside it. Racket World does the same in Racket.

Four ideas make this work:

  1. Late binding. The desktop looks up a name each time it needs it, so a new definition takes effect at once.
  2. Live loading. The desktop watches folders. It loads a file you save and drops the app when you delete the file.
  3. Error containment. You will break things in a system you change as it runs. A broken window must not stop the others.
  4. Environments. Sometimes you want to try code apart from the world, so a REPL can have its own namespace.

These ideas also matter for AI work. A program that hosts code written by a coding agent needs fast feedback, a record of errors, and a way to limit what a bad definition can break. Note that Racket World does not sandbox its apps. They run with your permissions, so read generated code before you load it.

Racket World with a REPL, Clock, Boids, and Widgets

Project structure

The code for this chapter is in the directory Racket-AI-book/source-code/racket_world. It has about 8,200 lines of Racket plus the tests, so this chapter shows the parts that carry the four ideas and gives complete listings for the small apps.

Folder What it holds
core/ theme, drawing, windows and events, environments, the loader
kits/ widgets, text editing, pixmaps and paints
looks/ 11 styles, 18 palettes, 5 wallpapers
desktop-ui/ the native window, bars, menus, toasts, keys
apps/ REPL, Clock, Settings, Monitor, Tasks, Environments
demo/ Life, Boids, Sketch, Springies, Rings, Widgets
lang/ the #lang racket_world language
examples/ four small apps and a palette

The project needs only the full Racket distribution.

A first app

One file is one app. Here is the complete file examples/counter.rkt. A click adds one to the count, and the 0 key resets it:

 1 #lang racket_world
 2 ;; The smallest app. Copy it to ~/racket_world.d/apps/ while the desktop runs:
 3 ;; it is in the launcher within a second.
 4 
 5 (define-app (counter) "Counter"
 6   (open-window "Counter" #:size '(240 . 100)
 7     #:count 0
 8     #:draw (lambda (win w h)
 9              (text-draw-centered 0 0 w h
10                                  (number->string (window-ref win 'count 0))
11                                  'accent 'big))
12     #:mouse-down (lambda (win x y button clicks)
13                    (window-set! win 'count (add1 (window-ref win 'count 0))))
14     #:key (lambda (win key mods)
15             (when (eqv? key #\0) (window-set! win 'count 0)))))

The form define-app defines a procedure named counter and lists it in the launcher. The procedure opens one window. Each handler is a keyword argument that takes a procedure, and the desktop calls the handler when its event occurs.

Any option that is not a handler or a placement option is a property of the window. Here #:count 0 makes a property, window-ref reads it, and window-set! changes it and asks for a redraw. The #:draw handler is the only place to draw. The color 'accent is a theme key, so the number changes color when the theme changes.

Copy the file into ~/racket_world.d/apps/ while the desktop runs, and within about a second the launcher lists it.

Options in two spellings

Schevana passes options as quoted symbols: 'size '(240 . 100). Racket programmers expect keywords: #:size '(240 . 100). The port accepts both, so you can move Schevana examples over with few changes. This macro from core/base.rkt does the work:

 1 ;; (define-opts (name pos ... . opts) body ...)
 2 ;; A procedure whose options may be given as symbols, Schevana's way
 3 ;; ('size '(300 . 200)), or as Racket keywords (#:size '(300 . 200)).
 4 ;; A keyword given #f is the same as leaving the option out.
 5 (define-syntax (define-opts stx)
 6   (syntax-case stx ()
 7     [(_ (name . formals) body ...)
 8      #'(define name
 9          (let ([proc (let ([name (lambda formals body ...)]) name)])
10            (procedure-rename
11             (make-keyword-procedure
12              (lambda (kws vals . args)
13                (apply proc
14                       (append args
15                               (keywords->plist*  kws vals))))
16              proc)
17             'name)))]))
18 
19 ;; (a #t is a flag alone, a #f is dropped)
20 (define (keywords->plist* kws vals)
21   (append*
22    (for/list ([k (in-list kws)] [v (in-list vals)] #:when v)
23      (define s (string->symbol (keyword->string k)))
24      (if (eq? v #t) (list s #t) (list s v)))))

The procedure make-keyword-procedure wraps a procedure that takes a property list. The wrapper turns keywords into symbol and value pairs and appends them to the other arguments.

An app that the REPL can change

A file with no #lang line holds plain forms. The desktop evaluates them in the world’s own namespace, which Racket World calls “/”. Here is the complete file examples/stopwatch.rkt:

 1 ;; An app of plain forms, with no #lang: what it defines belongs to the world,
 2 ;; so redefining stopwatch-text at a REPL changes the open window at once.
 3 
 4 (define (stopwatch-text ms)
 5   (define tenths (quotient (exact-round ms) 100))
 6   (format "~a.~a s" (quotient tenths 10) (remainder tenths 10)))
 7 
 8 (define (stopwatch-icon x y s flags)
 9   (ui-icon-grid (x y s)
10     (fill-box 10 1.5 4 3 (icon-ink flags 'accent) 1)
11     (stroke-circle 12 13.5 8.5 (icon-ink flags 'accent) 2)
12     (draw-line 12 13.5 15.5 9.5 (icon-ink flags 'text) 2)))
13 
14 (define-app (stopwatch) "Stopwatch" #:icon stopwatch-icon
15   (define start (now-ms))
16   (define stopped #f)
17   (open-window "Stopwatch" #:size '(240 . 100)
18     #:open window-frame-soon!
19     #:frame (lambda (win t)
20               (unless stopped
21                 (invalidate! win)
22                 (window-frame-soon! win)))
23     #:mouse-down (lambda (win x y button clicks)
24                    (if stopped
25                        (begin (set! start (now-ms)) (set! stopped #f) (window-frame-soon! win))
26                        (set! stopped (- (now-ms) start)))
27                    (invalidate! win))
28     #:draw (lambda (win w h)
29              (text-draw-centered 0 0 w h (stopwatch-text (or stopped (- (now-ms) start)))
30                                  (if stopped 'green 'text) 'big))))

The app opens a window that redraws each frame until you click it. The draw handler calls stopwatch-text, a name in “/”. If you redefine stopwatch-text at the REPL, the open window shows the new format on its next frame. A module app does not offer this, because a module’s names are its own. Use a module to protect names and plain forms to expose them.

Idea 1: Late binding

The wallpaper, the bars, the menus, and the toasts are parts of the desktop that a user may redefine. The macro define-part in core/theme.rkt makes each one:

1 (define-syntax-rule (define-part (name name* arg ...) body ...)
2   (begin
3     (define (name* arg ...) body ...)
4     (define (name arg ...)
5       (define w (world-value 'name))
6       (if (and (procedure? w) (not (eq? w name)))
7           (w arg ...)
8           ((theme-part 'name) arg ...)))
9     (theme-default! 'name name*)))

A part has two names. For the wallpaper, draw-wallpaper* is the built-in version, and draw-wallpaper is the name the desktop calls. Each call checks “/” for a procedure with that name. If you defined one, the call runs yours. If not, the call runs the one the theme names, which is the built-in version by default. To undo a change, evaluate (define draw-wallpaper draw-wallpaper*).

A lookup by name costs more than a direct call, and the desktop makes many each frame. The file core/world.rkt caches the values, and world-changed! clears the cache after each evaluation in “/”:

 1 ;; What "/" defines may have changed: look names up again.
 2 (define (world-changed!)
 3   (set! cache (make-hasheq)))
 4 
 5 (define (world-define! name value)
 6   (when *ns*
 7     (namespace-set-variable-value! name value #t *ns*)
 8     (world-changed!)))
 9 (define (world-undefine! name)
10   (when *ns*
11     (with-handlers ([void void])
12       (namespace-undefine-variable! name *ns*))
13     (world-changed!)))

Theme layers

Late binding covers looks as well as code. A theme setting, such as 'accent, comes from the first layer that has it. This is the lookup from core/theme.rkt:

 1 ;; Returns (values value layer) before any rule is run.
 2 (define (lookup style key)
 3   (define-syntax-rule (try e layer next)
 4     (let ([v e]) (if (eq? v absent) next (values v layer))))
 5   (try (plist-ref *overrides* key absent) 'overrides
 6    (try (plist-ref (style-changes style) key absent) 'changes
 7     (try (style-lookup style key) 'style
 8      (try (if (eq? key 'palette)
 9               absent
10               (plist-ref (palette-colors (theme-in style 'palette)) key absent))
11           'palette
12       (try (hash-ref *defaults* key absent) 'built-in
13        (values absent #f)))))))

The local macro try uses the first value found and otherwise goes on to the next layer. The layers, in order, are your overrides for every style, your changes to this style, the style and its parents, the palette, and the built-in defaults. A setting may also be a rule: a delayed expression that reads other settings. The theme computes a rule when code first reads it, and reports an error if a rule depends on itself.

Idea 2: Live loading

The file core/loader.rkt watches the folders. For each file that loads, it keeps a stamp made from the modification time and the file size. A timer calls this procedure about once a second:

 1 ;; Loads what is new or changed, unloads what is gone.
 2 (define (scan-user-files!)
 3   (define files (map simple-form-path (all-files)))
 4   (for ([p (in-list (hash-keys *loaded*))] #:unless (member p files))
 5     (unload! p)
 6     (tell 'removed p))
 7   (for ([p (in-list files)])
 8     (define l (hash-ref *loaded* p #f))
 9     (define s (stamp-of p))
10     (when (and s (or (not l) (not (equal? s (loaded-stamp l)))))
11       (define ok? (load-app-file! p))
12       (tell (cond [(not ok?) 'failed] [l 'changed] [else 'added]) p)
13       (invalidate-all!))))

The first loop unloads apps whose files are gone. The second loads files that are new or that have a changed stamp. Comparing stamps once a second is a simple method that works on every platform.

Loading a Racket module a second time takes some care:

 1 (define (load-module! path)
 2   (define name (make-resolved-module-path path))
 3   (define stx
 4     (parameterize ([read-accept-reader #t] [read-accept-lang #t]
 5                    [read-accept-compiled #f] [current-load-relative-directory (path-only path)])
 6       (call-with-input-file path
 7         (lambda (in)
 8           (port-count-lines! in)
 9           (with-module-reading-parameterization
10             (lambda () (check-module-form (read-syntax path in)
11                                           (object-name-of path) path)))))))
12   (parameterize ([current-module-declare-name name]
13                  [current-load-relative-directory (path-only path)]
14                  ;; so that it can be declared again when the file changes
15                  [compile-enforce-module-constants #f])
16     (eval stx))
17   (dynamic-require path #f)
18   ;; what it provides is the world's too
19   (namespace-require path))

The loader reads the source and evaluates the module form itself. Setting compile-enforce-module-constants to #f lets the loader declare the module again when the file changes. The last line requires the module into “/”, so a REPL can call what the app provides.

The procedure load-app-file! records the result:

 1 ;; Loads one file, remembering what it registers. Returns #t if it loaded.
 2 (define (load-app-file! path0)
 3   (define path (simple-form-path path0))
 4   (define before-looks (list (styles) (palettes) (wallpapers)))
 5   (define err
 6     (with-handlers ([exn:break? (lambda (e) (raise e))]
 7                     [void (lambda (e) e)])
 8       (parameterize ([current-namespace (world-namespace)]
 9                      [current-app-source path])
10         (if (module-file? path) (load-module! path) (load-forms! path)))
11       #f))
12   (world-changed!)
13   (define now-apps (filter (lambda (a) (equal? (app-source a) path)) (apps)))
14   (define old (hash-ref *loaded* path #f))
15   (define new-looks
16     (append (for/list ([n (remove* (car before-looks) (styles))]) (cons 'style n))
17             (for/list ([n (remove* (cadr before-looks) (palettes))]) (cons 'palette n))
18             (for/list ([n (remove* (caddr before-looks) (wallpapers))]) (cons 'wallpaper n))))
19   (hash-set! *loaded* path
20              (loaded path (stamp-of path) err now-apps
21                      (remove-duplicates (append new-looks (if old (loaded-looks old) '())))))
22   (when err
23     (report-error! (path->string (file-name-from-path path)) err))
24   (not err))

It catches all errors except a break, which is how a user interrupts the program. A file that fails to load keeps its stamp, so the desktop reports the error once and tries again when you save the file.

Idea 3: Error containment

Every window handler except draw runs through this procedure in core/windows.rkt:

 1 ;; Calls one of win's handlers, if it has it; #t if it did. An error crashes
 2 ;; only this window.
 3 (define (call-handler win key . args)
 4   (define h (hash-ref (window-handlers win) key #f))
 5   (cond
 6     [(and h (or (not (window-error win)) (eq? key 'close)))
 7      (define t0 (now-ms))
 8      (with-handlers ([not-break? (lambda (e) (crash! win key e))])
 9        (parameterize ([current-window win] [current-app (window-app win)])
10          (with-style (window-style win)
11            (lambda () (apply h win args)))))
12      (set-window-cost! win (+ (window-cost win) (- (now-ms) t0)))
13      #t]
14     [else #f]))
15 
16 (define (crash! win key e)
17   (report-error! (format "~a's ~a" (window-title win) key) e)
18   (set-window-error! win e)
19   (invalidate! win))
20 
21 (define (window-retry! win)
22   (set-window-error! win #f)
23   (when (hash-ref (window-handlers win) 'frame #f) (window-frame-soon! win))
24   (invalidate! win))

If a handler raises an error, crash! records it and marks that window. The window then shows a page with the error in place of its content, and the rest of the desktop goes on. Drawing code uses the same method. Once you fix the problem, window-retry! clears the error.

Error handling alone cannot stop an endless loop. All window handlers run in one event thread, so a loop in a handler freezes the desktop, and you must press Ctrl+C in the terminal to quit. For long work, use spawn, from core/world.rkt:

 1 (define (spawn name thunk)
 2   (define cust (make-custodian))
 3   (define go (make-semaphore 0))
 4   (define id (atomically (begin0 next-id (set! next-id (add1 next-id)))))
 5   (define p #f)
 6   (define th
 7     (parameterize ([current-custodian cust])
 8       (thread
 9        (lambda ()
10          (semaphore-wait go)
11          (with-handlers ([exn:break? (lambda (e) (set-proc-state! p 'stopped))]
12                          [void (lambda (e)
13                                  (set-proc-state! p 'failed)
14                                  (set-proc-result! p e)
15                                  (report-error! name e))])
16            (set-proc-result! p (thunk))
17            (set-proc-state! p 'done))
18          (retire! p)))))
19   (set! p (proc id (format "~a" name) th cust (now-ms) 'running #f))
20   (atomically (set! *procs* (append *procs* (list p))))
21   (semaphore-post go)
22   ((unbox proc-changed-hook))
23   p)
24 
25 (define (retire! p)
26   (atomically (set! *procs* (remq p *procs*)))
27   ((unbox proc-changed-hook)))
28 
29 (define (kill! p)
30   (unless (proc-done? p) (set-proc-state! p 'killed))
31   (retire! p)
32   (custodian-shutdown-all (proc-custodian p)))

Each process has its own thread and its own custodian, the Racket object that manages threads, ports, and similar resources. The procedure kill! shuts down the custodian, which frees them all. The new thread waits on a semaphore so that it cannot finish before spawn has stored the proc structure.

Idea 4: Environments

A REPL can work in “/” or in an environment of its own. The file core/env.rkt makes four kinds:

REPL What a define does
(repl) changes the running world
(repl 'private) stays in an environment that only reads the world
(repl 'world) stays in an environment with all the world’s names
(repl 'pure) plain Racket
(repl 'sandbox) racket/sandbox: no files or network
(repl "core/windows.rkt") works inside one of the world’s modules

The first five rows are the world itself and the four kinds. The last row is an environment inside a module. Start the desktop with ./desktop --hacker to redefine names there.

This procedure makes the four kinds:

 1 (define (env-make! kind [path (fresh-path kind)] #:parent [parent "/"])
 2   (when (env-find path) (error 'env-make! "there is already an environment ~a" path))
 3   (define-values (ns evaluator)
 4     (case kind
 5       [(pure)
 6        (define ns (make-base-empty-namespace))
 7        (parameterize ([current-namespace ns]) (namespace-require 'racket))
 8        (values ns #f)]
 9       [(private world)
10        (define ns (fresh-namespace))
11        (parameterize ([current-namespace ns])
12          (namespace-require 'racket)
13          (case kind
14            [(world)
15             (namespace-require api-path)
16             ;; and the apps, which are the world's own definitions
17             (for ([n (in-list (world-definitions))])
18               (namespace-set-variable-value! n (lookup n) #t ns))
19             (for ([n (in-list (apps))])
20               (namespace-set-variable-value! n (app-procedure n) #t ns))]
21            [else
22             (for ([n (in-list readers)])
23               (define v (lookup n))
24               (when v (namespace-set-variable-value! n v #t ns)))]))
25        (values ns #f)]
26       [(sandbox)
27        (define ev
28          (parameterize ([current-library-collection-links
29                          ;; (the sandbox reads only paths there)
30                          (filter (lambda (l) (not (hash? l)))
31                                  (current-library-collection-links))]
32                         [sandbox-output 'string] [sandbox-error-output 'string]
33                         [sandbox-memory-limit 128] [sandbox-eval-limits '(30 64)])
34            (make-evaluator 'racket)))
35        (values #f ev)]
36       [else (error 'env-make! "the kinds are ~a" env-kinds)]))
37   (define e (env path kind ns evaluator parent
38                  (if ns (parameterize ([current-namespace ns])
39                           (for/hasheq ([s (in-list (namespace-mapped-symbols))]) (values s #t)))
40                      #hasheq())))
41   (atomically (set! *envs* (append *envs* (list e))))
42   (changed!)
43   e)

Racket’s namespaces do most of the work. A pure environment starts empty and requires racket. The private and world kinds share the module instances of the running world, and the case expression decides which names to add. The sandbox kind uses racket/sandbox, with a memory limit of 128 MB, and limits each evaluation to 30 seconds and 64 MB.

Only the sandbox kind guards against hostile code. The private kind keeps your definitions apart, but code there can still use files and the network.

A widget app

The widget kit in kits/ui.rkt follows Schevana’s immediate-mode model. The draw handler calls one procedure for each widget, where the widget goes, between ui-begin! and ui-end!. The kit draws the widget, notes where you can press it, and the app keeps only its own data.

This is the tip calculator from the project’s README. Save it as ~/racket_world.d/apps/tip.rkt:

 1 #lang racket_world
 2 
 3 (define-app (tip) "Tip"
 4   (define ui (make-ui))
 5   (define bill "42.00")
 6   (define percent 18)
 7   (define (money x) (string-append "$" (~r x #:precision '(= 2))))
 8   (define (draw win w h)
 9     (define ch (ui-control-height))
10     (define amount (or (string->number bill) 0))
11     (define extra (if (real? amount) (* amount percent 1/100) 0))
12     (ui-begin! ui)
13     (define y
14       (ui-form ui 'form 20 20 (- w 40)
15         (list
16          (list "Bill" ch
17                (lambda (x y w)
18                  (ui-text-field ui 'bill x y w ch bill
19                                 (lambda (s) (set! bill s) (invalidate! win)))))
20          (list "Percent" (ui-slider-height)
21                (lambda (x y w)
22                  (ui-slider ui 'percent x y w percent 0 30
23                             (lambda (v) (set! percent v) (invalidate! win))))))))
24     (draw-text 20 y (format "~a% is ~a" percent (money extra)) 'accent 'heading)
25     (ui-button ui 'copy 20 (+ y 34) 90 ch "Copy"
26                (lambda ()
27                  (clipboard-put! (money extra))
28                  (notify "Copied" 'green)))
29     (ui-end! ui w h))
30   (apply open-window "Tip" #:size '(300 . 180)
31     #:draw draw
32     (ui-handlers ui)))

The three variables ui, bill, and percent hold all of the app’s state. There is no event code for the slider. Its callback sets percent and asks for a redraw, and the next draw shows the new tip. The call to ui-handlers supplies the mouse and key handlers for the kit.

Running the code

Start the desktop from the project directory:

1 ./desktop

Press F1 to open the launcher (Cmd+K also works on a Mac), type a few letters of an app’s name, and press Enter. On a Mac, you may need to hold Fn with the F keys. At the REPL in the desktop, try:

1 (clock)                                    ; an app is a procedure
2 (set-theme! 'accent #xff9e64)              ; recolor the world
3 (set-style! 'spine)                        ; (styles) and (palettes) list them
4 (move-window! (find-window 'clock) 40 60)
5 (define (draw-wallpaper w h)               ; redefine part of the desktop
6   (fill-gradient 0 0 w h #x102030 #x301020))

You can also run the world with no window, which helps with scripts and tests. The -e option evaluates a form:

1 ./desktop --headless --no-repl \
2   -e "(begin (set-theme! 'accent #xff9e64) (printf \"accent: ~a\n\" (theme-source 'accent)))" \
3   -e "(begin (set-style! 'spine) (printf \"in spine: ~a\n\" (theme-source 'accent)))" \
4   -e "(begin (set-style! 'mac) (printf \"back in mac: ~a\n\" (theme-source 'accent)))" \
5   -e "(begin (define p (env-make! 'private \"/lab\")) (env-eval p '(define only-here 1)) (printf \"/lab defines: ~a\n\" (env-own-names p)))" \
6   -e "only-here"

Here is the output. Error messages go to standard error, so the last message may appear before the other lines:

1 accent: (changes mac 16752228)
2 in spine: (built-in 8037111)
3 back in mac: (changes mac 16752228)
4 /lab defines: (only-here)
5 only-here: undefined;
6  cannot reference an identifier before its definition
7   in module: top-level

The second example needs counter.rkt, stopwatch.rkt, and tip.rkt in your apps folder. It prints each file’s apps and load error, opens the three apps, and redefines a name that the stopwatch uses:

1 ./desktop --headless --no-repl \
2   -e "(for ([f (loaded-files)]) (printf \"~a ~a\n\" (loaded-apps f) (loaded-error f)))" \
3   -e "(begin (counter) (tip) (stopwatch) (printf \"~a\n\" (map window-title (windows))))" \
4   -e "(begin (printf \"~a\n\" (stopwatch-text 12345))
5              (define (stopwatch-text ms) (format \"~a ms\" (exact-round ms)))
6              (printf \"~a\n\" (stopwatch-text 12345.2)))"
1 (counter) #f
2 (stopwatch) #f
3 (tip) #f
4 (Stopwatch Tip Counter)
5 12.3 s
6 12345 ms

The tests drive a whole world with injected events and open no window:

1 $ raco test tests
2 raco test: (file "tests/world-test.rkt")
3 #t
4 20 tests passed

Interpreting the results

Theme layers. The call to set-theme! changed 'accent in the mac style. The result of theme-source gives the layer, the style where it applies, and the value; 16752228 is #xff9e64 in decimal. The spine style has no such change, so the value there came from the built-in layer. The change was still there when we went back to mac.

Environments. The name only-here exists in /lab and not in the world. The final error is the result we want.

Live loading and late binding. An error value of #f means the file loaded. The list of windows puts the newest first. The stopwatch formatted the same time two ways, because the second call found the new definition of stopwatch-text.

Error containment. One test opens a window whose draw handler evaluates (car 5):

 1 (test-case "a crash stays in its own window, and can be retried"
 2   (clear-errors!)
 3   (ev "(define broken? #t)")
 4   (define w (ev "(open-window \"Bad\" #:draw (lambda (win w h) (when broken? (car 5))))"))
 5   (frame!)
 6   (check-true (exn? (window-error w)))
 7   (check-equal? (length (recent-errors)) 1)
 8   (ev "(set! broken? #f)")
 9   (window-retry! w)
10   (frame!)
11   (check-false (window-error w))
12   (clear-errors!)
13   (close-all!))

The window crashes and the desktop records one error. The test then changes broken? to #f, retries the window, and finds no error. The window recovers without a restart.

How the port differs from Schevana

Schevana is the larger and more capable system. This port:

  • Has no GPU code: no compute shaders, no Pipeline, no frame tape, and no profiler flags. The form define-paint runs a Racket procedure for each pixel on the CPU.
  • Has eleven of Schevana’s styles and no bitmap fonts. Its Genera, Interlisp, and OPEN LOOK styles use system fonts and are simpler than the originals.
  • Has no crew, worklets, vats, host apps, Boids 3D, or games.
  • Adds folder watching, so apps load with no call to reload!. It also adds a native menu bar, and its Tasks app keeps its tasks.

Wrap up

Racket World keeps Schevana’s main idea: the desktop is made of values that you can look up, replace, and break while it runs. We saw a part macro that binds names late, a loader that reloads modules, handlers that contain errors, and namespaces that keep experiments apart. You can use each of these in other Racket programs.

I thank Pavel Uvarov and Eduardo Cavazos once more. They designed and built the system that this port follows, and they shared it under a license that lets us learn from it. Please visit Schevana and run the original.

Optional practice problems

  1. Change counter.rkt so that the up and down arrow keys add and subtract one. A key handler gets a character or a symbol such as left.
  2. Add a “Split between” field to the tip app and show the amount for each person. Handle a value of zero.
  3. Redefine draw-wallpaper to draw a grid of circles whose color comes from the theme. Then restore the built-in version.
  4. Write an app whose draw handler fails when you press a key. Fix the cause at the REPL and use window-retry! to recover.
  5. Write an app that uses spawn to call an LLM with code from an earlier chapter. Show the answer when it arrives, and add a button that calls kill!. Use run-in-world for changes to the window.
  6. Write a palette file modeled on examples/dusk.rkt and choose it with set-theme!.
  7. Read the source of one Schevana app that this port leaves out, and port it. Credit its authors in your file.