Extending DrScheme

DrScheme supports two forms of extension to the programming environment:

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 Scheme source file defines a teachpack (although the file may access other files via require). The file must contain a module, according to the naming convention laid out in the MzScheme manual (the name of the file must be the name of the module, with an additional .scm or .ss extension on the filename). 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 example, the following teachpack provides a lazy cons implementation. To test it, be sure to save it in a file named lazycons.scm.

(module lazycons mzscheme
  (provide (rename :lcons lcons) lcar lcdr)

  (define-struct lcons (hd tl))

  (define-syntax (:lcons stx)
    (syntax-case stx ()
      [(_ hd-exp tl-exp)
       (syntax (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 directory of the teachpack directory in the PLT installation.

4.2  Tools

A separate manual describes the mechanism for defining a tool. See PLT Tools: DrScheme Extension Manual.

4.3  Environment Variables

This section lists the environment variables that affect DrScheme's behavior. See the MzScheme manual for general information about environment variables.