<<

DrScheme A Pedagogic Programming

Environment for Scheme

Rob ert Bruce Findler Cormac Flanagan Matthew Flatt

Shriram Krishnamurthi and

Department of Computer Science

Rice University

Houston Texas

Abstract Teaching intro ductory computing courses with Scheme el

evates the intellectual level of the course and thus makes the sub ject

more app ealing to students with scienti interests Unfortunatelythe

p o or quality of the available programming environments negates many

of the p edagogic advantages Toovercome this problem wehavedevel

op ed DrScheme a comprehensive programming environmentforScheme

It fully integrates a graphicsenriched editor a multilingua l parser that

can pro cess a hierarchyofsyntactically restrictivevariants of Scheme

a functional readevalprint lo op and an algebraical ly sensible printer

The environment catches the typical syntactic mistakes of b eginners and

pinp oints the exact source lo cation of runtime exceptions

DrScheme also provides an algebraic stepp er a syntax checker and a

static debugger The rst reduces Scheme programs including programs

with assignment and control eects to values and eects The to ol is

useful for explainin g the semantics of linguistic facilities and for studying

the b ehavior of small programs The syntax c hecker annotates programs

with fontandcolorchanges based on the syntactic structure of the pro

gram It also draws arrows on demand that p oint from b ound to binding

o ccurrences of identiers The static debugger roughly sp eaking pro

vides a typ e inference system with explanatory capabilitie s Preliminary

exp erience with the environmentshows that Rice University students

nd it helpful and that they greatly prefer it to shell or Emacsbased

systems

Keywords Programming Environments Scheme Programming Ped

agogy Algebraic Evaluation Static Debugging Teaching programming

to b eginning students

Problems with Teaching Scheme

Over the past ten years Scheme has b ecome the most widely used functional

in intro ductory courses A United Stateswide countin

put Scheme in fourth place with b ehind Pascal Ada

and CC when group ed together SML is the only other

functional language listed at Schemes success is primarily due to Ab el

son and Sussmans seminal b o ok on their intro ductory course at MIT Their

course proved that intro ductory programming courses can exp ose students to

the interesting concepts of computer science instead of listing the syntactic con

ventions of currently fashionable programming languages

When Rice University implemented an MITstyle course the instructors en

countered four signicant problems with Scheme and its implementations

Since the syntax of standard Scheme is extremely lib eral simple notational

mistakes pro duce inexplicable results or incomprehensible error messages

The available implementations do not pinp oint the source lo cation of run

time errors

The Lispstyle output syntax obscures the p edagogically imp ortant connec

tion b etween program execution and algebraic expression evaluation

The hidden imp erative nature of Schemes readevalprintloopintro duces

subtle bugs that easily frustrate students

In contrast to exp erienced Scheme programmers who have often unconsciously

develop ed workarounds for these problems students are confounded bythe

resulting eects As a result some students dismiss the entire mostlyfunctional

approach to programming b ecause they mistake these environmental problems

for aws of the underlying functional metho dology

To address these problems wehave built DrScheme a Scheme environment

targeted at b eginning students The environment eliminates all problems men

tioned ab ovebyintegrating program editing and evaluation in a semantically

consistent manner DrScheme also contains three additional to ols that facilitate

teaching The rst one is a symb olic stepp er It mo d

els the execution of functional and imp erativeScheme programs as algebraic

reductions of programs to answers and their eects The second to ol is a syn

tax checker It annotates programs with font and color changes based on the

syntactic structure of the program and p ermits students to explore the lexical

structure of their programs with arrows overlaid on the program text The third

auxiliary to ol is a static debugger that infers what set of values an expression

may pro duce and howvalues ow from expressions into variables It exp oses

p otential safety violations and up on demand explains its reasoning by drawing

value ow graphs over the program text

The second section of this pap er discusses the p edagogy of Rice Universitys

intro ductory course and motivates many of the fundamental design decisions of

DrScheme but it should b e skipp ed on a rst reading if the reader is familiar

Data Description A list of numbers is either

null the empty list or

cons n lon where n is a number and lon is a list of numb ers

End

dene length alon

cond

null alon

cons alon add length cdr alon

dene fahrenheitcelsius d

d

Fig The design of a function

with teaching Scheme The third section presents DrScheme and explains how

it solves the ab ove problems esp ecially in the context of Rice Universitys intro

ductory course The fourth section briey explains the additional to ols The last

three sections discuss related work present preliminary exp eriences and suggest

p ossible uses in the functional programming community

Rice Universitys Intro ductory Computing Course

Rice Universitys intro ductory course on computing fo cuses on levels of abstrac

tion and how the algebraic mo del and the physical mo del of computation give

rise to the elds fundamental concerns The course consists of three segments

The rst segmentcovers functional program design and algebraic evaluation

The second segment is dedicated to a study of the basic elements of machine

organization machine language and assembly language The course ends with

an overview of the imp ortant questions of computer science and the key elements

of a basic computer science curriculum

The intro duction to functional program design uses a subset of Scheme It

emphasizes program design and the connection b etween functional programming

and secondary scho ol algebra In particular the course rst argues that a pro

gram fragment is a function that consumes and pro duces data and that the

design of programs or fragments must therefore b e driven by an analysis of

these sets of data The course starts out with the design of listpro cessing func

tions without relying on the fact that lists are a builtin typ e of data Students

quickly learn to describ e such data structures rigorously and to derive functions

from these descriptions see gure

Once the program is designed students study howitworks based on the

familiar laws of secondary scho ol algebra Not counting the primitivelaws of

arithmetic twolaws suce the law of function application and the

law of substitution of equals byprovably equals A go o d rst example is an

application of the temp erature conversion function from gure

fahrenheitcelsius

fahrenheitcelsius

Students know this example from their early scho oling and can identify with it

For examples that involve lists students must b e taught the basic laws of

listpro cessing primitives That is cons vlisavalue if v is a value and l a

list car cons vl v and cdr cons vl l for every value v and list l

From there it is easy to illustrate how the sample program works

length cons cons null

length cdr cons cons null add

add length cons null

add add length cdr cons null

add add length null

add add

In short algebraic calculations completely explain program execution without

any references to the underlying hardware or the runtime context of the co de

As the course progresses students learn to deal with more complex forms

of data denitions nonstructural recursion and accumulatorstyle programs

At the same time the course gradually intro duces new linguistic elements as

needed Sp ecically for the rst three weeks students work in a simple functional

language that provides only function denitions conditional expressions and

basic b o olean arithmetical and listpro cessing primitives Then the language

is extended with a facility for dening new data constructors and parallel and

recursive lo cal denitions The nal extension covers variable assignment and

data mutation With each extension of the language the course also intro duces

a set of appropriate design recip es and rewriting rules that explain the new

language features

At the end of the segment on program design students understand howto

construct programs as collections of functions and as ob jectoriented history

sensitive pro cedures They can evaluate programs by reducing them algebraically

to their values and eects and understand how to use these evaluations to reason

ab out the correctness and complexity of their designs

The Programming Environmen

DrScheme runs under Microsoft Windows Windows NT MacOS and the X

Fig The DrScheme window Windows NT version

Window System When it starts up it presents the programmer with a menubar

and a window consisting of three pieces the control panel the denitions upp er

window and the interactions lower window see gure The control panel has

buttons for imp ortant actions eg Save and Help The denitions windowisan

editor that contains a sequence of denitions and expressions The interactions

window whichprovides the same editing commands as the denitions window

implements a novel readevalprintloop

DrSchemes menubar provides vemenus File Edit Show SchemeandLan

guage The File and Edit menus contain the standard menu items In addition the

latter provides the EditjInsert Imagemenu item which allows the programmer

to insert images into the program text Images are treated as ordinary values

likenumb ers or symb ols

The Show menu controls the visibility of the subwindows The Scheme menu

allows programmers to indent comment and uncomment regions of text in the

uallows the studenttocho ose whichsub denitions window The Language men

languages of Scheme the syntax checker and evaluator accept

The control panel contains six buttons Save Check Syntax Analyze Exe

cute Break and HelpTheSave button saves the denitions from the denitions

window as a le Clicking the Check Syntax button ensures that the denitions

window contains a correctly formed program and then annotates the program

based on its syntactic and lexical structure see section The Analyze but

ton invokes the static debugger describ ed in section on the contents of the

Under Windows and X the menubar app ears at the top of the window under MacOS

the menubar app ears at the top of the screen

denitions window The Execute button executes the program in the denitions

window The Break button stops the current computation and the Help button

summons the online help facility for DrScheme

The denitions and interactions windows contain editors that are compatible

with typical editors on the various platforms Under X the editor has manyofthe

Emacs key bindings The Windows and MacOS versions have the standard

key bindings and menu items for those platforms

The remainder of this section motivates and describ es the new asp ects of the

core programming environment In particular the rst subsection describ es how

DrScheme can gradually supp ort larger and larger subsets of Scheme as students

gain more exp erience with the language and the functional programming phi

losophy The second subsection describ es how the denitions window and the

interactions window readevalprint lo op are co ordinated Finally the third

subsection explains how DrScheme rep orts runtime errors via source lo cations

in the presence of macros The remaining elements of DrScheme are describ ed

in section

Language Levels

Contrary to oftstated claims learning Scheme syntax p oses problems for b e

ginning students who are used to conventional algebraic notation Almost any

program with matching parentheses is syntactically valid and therefore has some

meaning For b eginning programmers that meaning is often unintended and as

a result they receive inexplicable results or incomprehensible error messages for

essentially correct programs

For example the author of the program

dene length l

cond

null l

else length cdr l

has lapsed into algebraic syntax in the second clause of the condexpression

Since the value of a condclause is the value of its last expression this version

of length always returns as a result puzzling any programmer and esp ecially

b eginning programmers

Similarly the program

dene length l

cond

null l

else length cdr l

is syntactically valid Its author also used algebraic syntax this time in the rst

condclause As a result this version of length erroneously treats its argument

eglist as a function and applies it to no arguments The resulting error

message apply list not a procedure is useless to b eginners

While these programs are awed their student authors should receive en

couragement since the aws are merely syntactic They clearly understand the

inductive structure of lists and its connection to the structure of recursive pro

grams Since Schemes resp onse do es not provide any insightinto the actual

error the students learning exp erience suers A go o d p edagogic programming

environment should provide a correct and concise explanations of the students

mistakes

Students also write programs that use keywords that they havenotyet b een

taught as identiers It is not the students fault for using those keywords in

correctly A programming environment should limit the language to the pieces

relevant for each stage of a course rather than leaving the entire language avail

able to trap unwary students

For example a studentmight write

dene length l start

cond

null l start

else length cdr l add begin

This program is buggy it has an unbound identier b egin But it generates

a strange syntax error compile illegal use of a syntactic form name

in begin The student cannot understand that they haveuncovered a new

part of the programming language

Eager students also attempt to use features that they havenotyet seen

in class For example they might try to use lo cal denitions b efore scop e is

describ ed in class Many students try to return more than one value from a

function by juxtap osing several expressions b ehind lambdaStudents with prior

exp erience in C or Pascal mightsolve a simple functional exercise with imp erative

features Again a go o d p edagogic programming environment should protect the

student from using language features that are inconsistent with the p edagogic

goals of a phase of the course

A natural solution for all of these problems is to stratify the programming

language into several levels Eachlevel should provide enough p ower to teach

a new set of constructs and programming paradigms and it must not allow

irrelevant language features to interfere with the goals of a teaching unit In

short a p edagogic programming environmentmust b e able to grow along with

the students through a course

DrScheme implements this stratication with four language levels The

studentcancho ose the appropriate language level via the LanguagejCongure

Language menu item Cho osing LanguagejCongure Language op ens a window

with a choice dialog item that displays the current language level The choice

dialog item mirrors the students language level A language consists of several

indep endent settings which are normally hidden from the student Clicking on

the Show Details button enlarges the dialog bringing a panel with all of the

language settings into view Figure sho ws the enlarged dialog

The description of a language level consist of three parts input syntax safety

prop erties and output syntax The input syntax is sp ecied through the Case

Fig DrSchemes language conguration dialog b oxXversion

Sensitive checkboxandavocabulary a set of syntactic forms The four pre

dened vo cabularies are Beginner Intermediate AdvancedandQuasiR RS

Eachvo cabulary corresp onds to a stage in Rice Universitys intro ductory course

Beginner includes denitions conditionals and a large class of functional prim

itives

Intermediate extends Beginner with structure denitions and the lo cal binding

constructs lo cal let letand letrec

Advanced adds supp ort for variable assignments data mutations as well as

implicit and explicit sequencing

QuasiR RS subsumes the Scheme language

The rst three blo cks of the table in gure sp ecify the exact syntactic content

of the various language levels The last blo ck describ es other prop erties of the

four language levels

The safety prop erties of DrScheme allow the studenttocho ose b etween con



formance with R RS and more sensible error rep orting They can b e sp ecied

with four checkboxes

Allow improp er lists

Allow set on undened identiers

Unmatched condcase is an error and

Signal undened variables when rst referenced

Beginner Intermediate Advanced QuasiR RS

p p p p

dene

p p p p

lambda

p p p p

cond if

p p p p

quoted symbols

p p p

denestruct

p p p

lo cal let let letrec

p p p

delay force

p p

set

p p

b egin b egin

p p

implicit b egin

p p

named let recur

p p

quoted lists

p p

quasiquote

p p

unquote

p p

callccletcc

p p

when unless

p p

if without else

p p p p

scheme primitives

p p p p

case sensitive

p

sharing in values

p

Allow improp er lists

p

Allow set on undened identiers

p

Unmatched condcase is an error

Fig Language Level Quick Reference

When the Allowimprop er lists is unchecked cons can only b e used to construct

lists its second argumentmust always b e either null or a cons cell The checkbox

Allow set on undened identiers controls whether set creates a new name at

the toplevel or signals an error for unb ound identiers If Unmatched condcase

is an error is on the implicit else clause in cond and case expressions signal a

runtime error If it is o the implicit else clause returns a dummyvalue

The Signal undened variables when rst referenced checkboxcontrols the lan

guages b ehavior when evaluating p otentially circular denitions Scheme evalu

ates recursive binding expressions by initializing all identiers b eing b ound to a

sp ecial tag value and then evaluating each denition and rebinding each iden

tier If the checkb ox is on an error is signaled when a variable still b ound to

one of the tag values is evaluated and if o errors are only signaled if the initial

value ows into a primitive function

The output syntax is determined bytheShowsharing in values checkbox

and the Printing choice When the Show sharing in values is on all sharing

within data structures is displayed in the output The Printing choice provides



three alternatives constructorstyle quasiquote style or R RS style Under con

structor style the list containing the numbers and prints out as list

Because it mirrors the input syntax for values constructor style output

is useful for general programs and mandatory for p edagogic programming see

section In contrast quasiquote style is a compromise b etween the construc

tor style output and the standard Scheme output style Like the former the

quasiquotestyle output matches quasiquote input syntax But by dropping the

leading quasiquote the output can also b e used as program text just likethe

output of the standard Scheme printer

InteractiveEvaluation

Many functional languages supp ort the interactiveevaluation of expressions via a

readevalprintlooprepl Abstractlyarepl allows students to b oth construct

new programs and evaluate expressions in the context of a programs denitions

Atypical repl implements those op erations by prompting the students to input

programs fragments The fragments are then evaluated and their results are

printed

Interactivity is primarily used for program exploration the pro cess of evaluat

ing expressions in the context of a program to determine its b ehavior Frequent

program exploration during developmentsa ves large amounts of conventional

debugging time Programmers use interactiveenvironments to test small com

p onents of their programs and determine where their programs go wrong They

also patch their programs with the repl in order to test p otential improvements

or bug xes by rebinding names at the toplevel

While interactive repls are sup erior to batch execution for program develop

ment they can intro duce confusing bugs into programs Since they allow adho c

program construction repls cause problems for the b eginner and exp erienced

programmer alike For example a student who practices accumulatorstyle trans

formations may try to transform the program

dene length l dene lengthhelper l n

lengthhelper l cond

null l n

else lengthhelper cdr l add n

into a version that uses lo cal denitions

dene length l

letrec helper lambda ln

cond

null l n

else lengthhelper cdr l add n

helper l

Unfortunately the student has forgotten to change one o ccurrence of length

helper to helper Instead of agging an error when this program is run the

traditional Scheme repl calls the old version of lengthhelper when length is

applied to a nonempty list The new program has a bug but the confusing

repl semantics hides the bug

Similar but even more confusing bugs o ccur when students program with

higherorder functions Consider the program

dene makeadder n

lambda m

mn

dene add makeadder

A student will quickly discover the bug by exp erimenting with add replace the

primitive with and reevaluate the denition of makeadder Unfortunately

the repl no longer reects the program b ecause add still refers to the old

value of makeadder Consequently add will still exhibit the bug confusing the

student The problem is exacerbated when higherorder functions are combined

with state

Exp erienced functional programmers have learned to avoid this problem by

using their repl in a batchoriented fashion They exit restart and reload a

program le after eachchange This action clears the state of the replwhich

eliminates bugs intro duced by ghosts of old programs Unfortunatelymanually

restarting the environment is b oth timeconsuming and errorprone

DrScheme provides and enforces this batchoriented style of interactive pro

gram evaluation in a natural way When the student is ready to test a program

a clickonthe Execute button submits the program to the interactions window

When the studentclicks on Executetherepl is set to its initial state and the

text from the denitions windowisevaluated in the fresh environment Thus the

repl namespace exactly reects the program in the denitions window Next

the studentevaluates test expressions in the repl After discovering an error

the student edits the denitions and executes the program again to test the new

denitions In short after every change to the program the student starts the

program afresh which eliminates the problems caused by traditional repls

Error Rep orting

A p edagogic programming environmentmust provide go o d runtime error re

p orting it is crucial to a students learning exp erience The programming en

vironmentmust catch errors as so on as they o ccur and provide meaningful ex

planations for them The explanations must include the runtime values that

caused the errors as well as the source lo cation of the misapplied primitives

Traditional Scheme programming environments fail in this regard for two

reasons First with the exception of EdScheme Scheme and inter

preters only implement a simplistic readevalprint lo op If this repl is executed

in a plain command shell it is imp ossible to relate errors to source lo cations in

general The historical solution is to execute the repl in an Emacs buer This

Fig DrScheme with a runtime error highlighted X Motif version

solution however do es not truly integrate the repl and its editing environment

so that the graphical capabilities of mo dern displays remain unexploited

Second Schemes macro facility tremendously complicates the map

ping from a runtime error to its source lo cation Since Schemes macro lan

guage allows arbitrary mappings on program text during compilation preserving

the original source lo cations for pieces of program text is dicult For example

Schemes let macro expands to a sequence of nested let expressions and those

let expressions then expand into lambda expressions Other macros duplicate

or delete p ortions of source text

DrScheme overcomes all three problems The underlying Scheme implementa

tion is safe and completely integrated into the editing environment Furthermore

the frontend of the Scheme implementation maintains a correlation b etween the

original program text and its macroexpanded version This correlation al

lows DrScheme to rep ort the source lo cation of runtime errors

Consider the example in gure The student has written an erroneous ver

sion of length When it is applied to list it recurs down the list and is

applied to null The function then returns null whichows into the primitive

generating a runtime error Then the runtime error is caughtby DrScheme

and the source lo cation of the misapplied primitive is highlighted With a little

eort any b eginning studentcannow x the bug

To ols

Thus far wehave seen how DrScheme straties Scheme into p edagogically use

ful pieces improves the readevalprint lo op and provides b etter error rep ort

ing This section fo cuses on the additional program understanding to ols that

DrScheme provides

Supp orting Reduction Semantics Printing and The Stepp er

As discussed in section Rice Universitys intro ductory course emphasizes the

connection b etween program execution and algebraic expression evaluation Stu

dents learn that program evaluation consists of a sequence of reductions that

transform an expression to a value in a context of denitions

Unfortunately traditional Scheme implementations do not reinforce that con

nection They typically use one syntax for values as input and a dierent

syntax for values as output For example the expression

map add list

evaluates to

whichgives students the mistaken impression that the original expression has

evaluated to an application of to and

DrScheme uses an output syntax for values called constructor syntax that



matches their input syntax Constructor syntax treats the primitives cons vec

uswhenavalue is printed the initial construc tor box etc as constructors Th

tor shows which subset contains the value

So in the the ab ove example DrScheme prints the value of

map add list

as

list

DrSchemes printer pro duces the same syntax for the values that Schemes re

duction semantics pro duces

More imp ortantly DrScheme also includes a to ol that enables students to

reduce a program to a value step by step This symb olic stepp er is based on

Felleisen and others work on reduction semantics for Scheme and MLlikelan

guages and can deal with all the features used in Rice Universitys

course including the entire functional sublanguage structure denitions vari

able assignment data structure mutation exceptions and other control mecha

nisms



A studentinvokes the stepp er bycho osing ToolsjStepp er By default the

stepp er shows every reduction step of a program evaluation While this is useful

list is used as shorthand for consecutive conses ending in null

The stepp er is not available in DrScheme version

Fig The stepp er X version

for a complete novice a full reduction sequence contains to o much information in

general Hence the stepp er p ermits the studenttocho ose which reduction steps

are shown or which subexpressions the stepp er is to fo cus on Ateach step the

studentcanchange these controls to view a more detailed reduction sequence

The stepp er window always displays the original program expression and

denitions together with the current state of the evaluation as a program see

gure For each step the stepp er explains its action b efore it pro ceeds In the

gure it indicates that it is ab out to lo okup length and replace it with its value

If reduction rules for imp erative language facilities require memory allo cations

they are intro duced as global denitions To fo cus students attention these

auxiliary denitions are hidden until mutated Students may also cho ose to view

thematintermediate stops

Students use the stepp er for two purp oses First they use it to understand

the meaning of new language features as they are intro duced in the course A

few sessions with the stepp er illustrates the b ehavior of new language constructs

b etter than any blackb oard explanation Second students use the stepp er to nd

bugs in small programs The stepp er stops when it encounters a runtime error

and p ermits students to movebackwards through the reduction sequence This

usage quickly explains the reasons for bugs and even suggests xes

Fig DrSchemes syntax checker MacOS version

Syntax Checking

Beginning programmers need help understanding the syntactic and lexical struc

ture of their programs DrScheme provides a syntax checker that annotates the

source text of syntactically correct programs based on the syntactic and lexical

structure of the program The syntax checker marks up the source text based on

ve syntactic categories primitives keywords b ound variables free variables

and constants

On demand the syntax checker displays arrows that p oint from b ound iden

tiers to their binding o ccurrence and from binding identiers to all of the their

b ound o ccurrences see gure Since the checker pro cesses the lexical structure

the program it can also b e used to rename b ound identiers If a student

checks a syntactically incorrect program the rst incorrect p ortion of the text

is highlighted and an error message is printed

Static Debugging

The most advanced DrScheme to ol is MrSpidey a static debugger which

subsumes the syntax checker but is computationally far more exp ensive It an

alyzes the current program using a new form of setbased analysis for

p otential safety violations That is the to ol infers constraints on the p otential

value owintheScheme program similar to the equational constraints of a

HindleyMilner typ e checker and builds a value ow graph for the program

For each primitive the static debugger determines whether or not the p otential

argumentvalues are legal inputs

Based on the results of the analysis the static debugger annotates the pro

t and color changes Primitive op erations that may b e misapplied gram with fon

are highlighted in red and those that the static debugger can prove are always

correctly applied are highlighted in green In print and on mono chrome displays

all primitives are b oldfaced and red primitives are underlined On demand the

static debugger annotates each program p ointwith

Fig MrSpidey The static debugger X version

its inferred value set and

arrows describing the inferred owofvalues that pro duced the value set

Using these markups a student can browse the invariants that approximate the

dynamic b ehavior of a program to identify which op erations are not provably

safe The student can evaluate the coverage of the set of program test cases and

tune the program to improve the accuracy of the generated invariants

For an illustration consider the program in the top of gure After the

static debugger completes its analysis it op ens a windowcontaining the analyzed

program with each primitive colored either red or green In this example add

is colored red which indicates that the static debugger cannot prove that the

argumentwillalways b e a numb er The student using a p opup menu can

now displaythevalue set of adds argument The static debugger resp onds by

inserting a b ox that contains the value set for the argument to the rightofthe

arguments text as in the top of gure This value set contains nullwhichis

why the static debugger concluded that add may b e misapplied Toseehow

null can owinto the argumentofadd the static debugger can also annotate

the program with an arrowpointing from the argumentofadd to the source

of null as in the b ottom of gure Since a recursive application of length can

trigger the owofnull into add as discussed in section the static debugger

has given the student the information needed to uncover the bug

Related Work

DrScheme seamlessly integrates a numb er of ideas that are imp ortant for teach

ing courses with functional languages esp ecially at the intro ductory level well

dened simple sublanguages a syntax checker with lexical scop e analysis a

readevalprintlooprepl with transparent semantics precise runtime error

rep orting an algebraic printer an algebraic stepp er and a fulledged static

debugger The restriction of the full language to a hierarchy of simplied sub

languages the syntax checker the algebraic stepp er for full Scheme the trans

parent repl and the static debugger are novel environmentcomponents that

no other programming environmentprovides

In lieu of source lo cations for runtime errors other Scheme implementations

provide tracers stackbrowsers and conventional breakp ointoriented debuggers

In our exp erience these to ols are to o complex to help novice students Worse

they encourage students with prior exp erience in Pascal or C to fall backinto

the tinkeruntilitworks approach of traditional imp erative program construc

tion

Other functional language environments provide some of the functionalityof

DrScheme Sp ecically SMLNJ provides a repl similar to the one describ ed

here for the module language of SML Unfortunately this is useless for

b eginners who mostly w ork with the core language Also CAML ML

Works and SMLNJ have go o d source rep orting for runtime errors but

due to the unicationbased typ e inference pro cess rep ort type errors of pro

grams at incorrect places and often display incomprehensible messages

Commercial programming environments for imp erative program

ming languages like C incorp orate a go o d p ortion of the functionalityfound

in DrScheme Their editors use online realtime syntax coloring algorithms the

runtime environments trap segmentation faults and highlight their source lo ca

tion whichismuch less useful than catching safety violations but still sup erior

to standalone replsofScheme and other functional languages Indeed their

debuggers serve as primitive repls though with much less exibility than the

repls that come with Scheme or SML None of them however provides lan

guage levels fulledged algebraic printers stepp ers or static debuggers which

wehave found to b e extremely useful for teaching purp oses

User Exp eriences

All four of the professors who teachtheintro ductory computer science course at

Rice University three of whom are indep endent of the development group use

DrScheme for the course DrScheme is used in the course on a weekly basis for

b oth the tutorials and the homework assignments Also the programming lan

guages course at Rice uses DrScheme for the weekly programming assignments

Unfortunatelywedonothaveanyquantitative data for comparing DrScheme to

other programming environments since all sections of the intro ductory course

and the programming languages course use DrScheme Still students who know

b oth Emacsbased Scheme environments and DrScheme typically prefer the lat

ter

Wehave also received enthusiastic rep orts from professors and teachers in

several countries of North America and Europ e who use DrScheme in their

classes Our announcement mailing list consists of nearly one hundred p eople

in academia and industry who use DrScheme and its application suite Weare

also aware of several commercial eorts that are incorp orating p ortions of our

suite into their pro ducts

Most of the complaints ab out DrScheme fall into two categories First run

ning DrScheme requires at least megabytes of memory on most op erating sys

tems and machines If a machine has less than the required minimum DrScheme

is extremely slowandmayeven crash Second since the development team only

uses a small subset of the supp orted platforms small platformdep endenterrors

can go undetected for some time We exp ect to eliminate b oth problems with

future research

Conclusion

The p o or quality of programming environments for functional languages dis

tracts students from the study of computer science principles The construction

of DrScheme overcomes these problems for Scheme

Many asp ects of DrScheme apply to functional languages other than Scheme

Any functional language b ecomes more accessible to the b eginner in an environ

ment that provides several w ellchosen language levels a functional readeval

print lo op accurate source highlighting for runtime errors and a stepping to ol

that reinforces the algebraic view of computation In addition typ ed languages

can b enet from graphical explanations of typ e errors like those of the static

debugger In general we hop e that DrSchemes success with students and teach

ers around the world inspires others to build programming environments for

functional languages based on p edagogic considerations

DrScheme is available on the web at httpwwwcsriceeduCSPLT

Acknowledgments

We greatly appreciate valuable feedback from R CartwrightandDPFriedman

on early drafts of this pap er

References

Ab elson H G J Sussman and J Sussman Structure and Interpretation of Com

puter Programs MIT Press

ATT Bell Labratories Standard ML of New Jersey

Blume M Standard ML of New Jersey compilation manager Manual accompa

nying SMLNJ software

Borland Borland C

Bourdoncle F Abstract debugging of higherorder imp erative languages In ACM

SIGPLAN ConferenceonProgramming Language Design and Implementation

pages

Cadence Research Systems Chez Scheme Reference Manual

Clinger W and J Rees The revised rep ort on the algorithmic language Scheme

ACM Lisp Pointers July

Dybvig R K R Hieb and C Bruggeman Syntactic abstraction in Scheme Lisp

and Symbolic Computation Decemb er

Felleisen M An extended calculus for Scheme In ACM Symposium

and Functional Programming pages

Felleisen M On the expressivepower of programming languages Scienceof

Computer Programming

Felleisen M and R Hieb The revised rep ort on the syntactic theories of sequential

control and state In Proceedings of Theoretical Computer Science pages

Findler R B and M Flatt PLT MrEd Graphical to olb oxmanual Technical

Rep ort TR Rice University

Flanagan C and M Felleisen Comp onen tial setbased analysis In ACM SIG

PLAN ConferenceonProgramming Language Design and Implementation

Flanagan C M Flatt S Krishnamurthi S Weirich and M Felleisen Catching

bugs in the web of program invariants In ACM SIGPLAN ConferenceonPro

gramming Language Design and Implementation pages May

Flatt M PLTMzScheme Language manual Technical Rep ort TR Rice

University

Francez N S Goldenb erg R Y Pinter M Tiomkin and S Tsur An environ

ment for logic programming SIGPLAN Notices July

Hanson C The MIT Scheme Team and A Cast of Thousands MIT Scheme

Reference

Harlequin Inc MLWorks

Harp er R P Lee F Pfenning and E Rollins Incremental recompilation for

Standard ML of New JerseyTechnical Rep ort CMUCS Carnegie Mel

lon University

Heintze N Set based analysis of ML programs In ACM Symposium on Lisp and

Functional Programming

Hsiang J and M Srivas A Prolog environment Technical Rep ort State

UniversityofNewYork at Stony Bro ok Stony Bro ok New York July

Kohlb ecker E E D PFriedman M Felleisen and B F Duba Hygienic macro

expansion In ACM Symposium on Lisp and Functional Programming pages

Kohlb ecker Jr E E Syntactic Extensions in the Programming Language Lisp

PhD thesis Indiana University August

Komorowski H J and S Omori A mo del and an implementation of a logic pro

gramming environment SIGPLAN Notices July

Koschmann T and M W Evens Bridging the gap b etween ob jectoriented and

logic programming IEEE Software July

Krishnamurthi S Zo diac A framework for buildin g interactive programming

to ols Technical Rep ort TR Rice University

Lane A Turb o Prolog revisited BYTE Octob er

LeroyX The Objective Caml system documentation and users guide

Metrowerks CodeWarrior

Microsoft Microsoft Developer Studio

Milner R M Tofte and R Harp er The Denition of StandardML MIT Press

Reid R J Firstcourse language for computer science ma jors Posting to

compedu Octob er

EdScheme A Modern Lisp

Schemers Inc and Terry Kaufman Scheme in colleges and high scho ols Available

on the web

URL httpwwwschemerscomschoolshtml

Stallman R GNU Emacs ManualFree Software Foundation Inc Mass Ave

Cambridge MA

Texas Instruments PC Scheme Users Guide Language ReferenceManual

Student Edition

Wadler P A critique of Ab elson and Sussman or why calculating is b etter than

scheming SIGPLAN Notices March

A

This article was pro cessed using the L T X macro package with LLNCS style E