Drscheme: a Pedagogic Programming Environment for Scheme
Total Page:16
File Type:pdf, Size:1020Kb
DrScheme A Pedagogic Programming Environment for Scheme Rob ert Bruce Findler Cormac Flanagan Matthew Flatt Shriram Krishnamurthi and Matthias Felleisen 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 scientic 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 programming language 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 functional programming 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 t 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