On this page:
4.1 Teachpacks
4.1.1 Adding Your Own Teachpacks to the Teachpack Dialog
4.1.2 Extending Help Desk Search Context
4.2 Environment Variables

4 Extending DrRacket

DrRacket supports four forms of extension to the programming environment: keybindings, teachpacks, scripts, and plugins.

Customization of the DrRacket environment is available via Preferences menu item, along the the facility to define new color schemes. Existing color-scheme packages are tagged “colorscheme”.

4.1 Teachpacks

Teachpacks are designed to supplement student programs with code that cannot be expressed in a teaching language. For example, to enable students to play hangman, we supply a teachpack that

All these tasks are beyond students in the third week and/or impose memorization of currently useless knowledge on students. The essence of the hangman game, however, is not. The use of teachpacks enables the students to implement the interesting part of this exercise and still be able to enjoy today’s graphics without the useless memorization.

A single Racket source file defines a teachpack (although the file may access other files via require). The file must contain a module (see Modules). Each exported syntax definition or value definition from the module is provided as a new primitive form or primitive operation to the user, respectively.

As an example, the following teachpack provides a lazy cons implementation. To test it, save the following in a file and add the file as a teachpack (or use require).

#lang racket
 
(provide (rename-out [:lcons lcons]) lcar lcdr)
 
(define-struct lcons (hd tl))
 
(define-syntax (:lcons stx)
  (syntax-case stx ()
    [(_ hd-exp tl-exp)
     #'(make-lcons
               (delay hd-exp)
               (delay tl-exp))]))
 
(define (lcar lcons) (force (lcons-hd lcons)))
(define (lcdr lcons) (force (lcons-tl lcons)))

Then, in this program:

(define (lmap f l)
  (lcons
   (f (lcar l))
   (lmap f (lcdr l))))
 
(define all-nums (lcons 1 (lmap add1 all-nums)))

the list all-nums is bound to an infinite list of ascending numbers.

For more examples, see the "htdp" sub-collection in the "teachpack" collection of the PLT installation.

4.1.1 Adding Your Own Teachpacks to the Teachpack Dialog

The Language|Add Teachpack... dialog is extensible in two ways. First, users can add teachpacks to the third column by clicking the button at the bottom of the column. These additions are stored in the preferences file, so one way to add site-specific teachpacks is to provide a default preferences file.

The first two columns are also extensible. When a collection has an "info.rkt" file (see "info.rkt" File Format) that defines htdp-teachpacks or 2htdp-teachpacks, then they are expected to be either a list of (collection-relative) paths containing teachpacks to add to the dialog, or the symbol 'all, which means that all of the (top-level) files in the collection that end with a module suffix (including ".rkt", ".ss", or ".scm") are teachpacks (except "info.rkt" or "info.ss").

4.1.2 Extending Help Desk Search Context

In How to Design Programs Teaching Languages, the search context for the Search in Help Desk for ... item in the pop-up menu can be extended by defining the 2htdp:teachpack-modules binding in the info.rkt file (see "info.rkt" File Format). The 2htdp:teachpack-modules binding should evaluate to a list of symbols representing the module paths to be included in the search context.

For example, the following info.rkt file

#lang info
 
(define scribblings '(("scribblings/intro101.scrbl")))
 
(define 2htdp:teachpack-modules
  '(intro101/file-operations intro101/iterated))

includes the modules intro101/file-operations and intro101/iterated in the help desk search context.

4.2 Environment Variables

Several environment variables can affect DrRacket’s behavior: