[an error occurred while processing this directive] [an error occurred while processing this directive]                 Modeling and Abstraction
Rice University
COMP 200
Elements of Computer Science
 
Functional Programming in Scheme


Scheme is a programming language designed to solve problems that can be inherently expressed in terms of functions.  Functional programming (FP) is formulating problems in terms of functions and writing programs as functions to solve the formulated problems.  Scheme is said to be a FP language because Scheme programs are expressed as collections of one or more functions.  

In this chapter, we will work on a series of problem solving in Scheme to gain some insight on what FP is.  We will do many of them in class on the computer.  We will use the book How to Design Programs extensively and DrScheme as the programming environment to program in Scheme.  When you run DrScheme, be sure to set the language level to Beginning Student using the Language menu: Language/Choose Language...

Basic Scheme Syntax

A Scheme expression can be either atomic or compound.

An atomic expression is, for now, something like a number or a variable name.

A compound expression is something that stats with a left parenthesis "(", followed by an operation name, followed by a sequence of zero or more Scheme expressions, and terminated by a right parenthesis ")".   For examples, (* 2 (+ 3 4)), (sqrt 100) are compound expressions.

Scheme expressions are said to be in prefix notation.

Exercises

  1. Write a function to compute the area of a rectangle.  (What input parameter(s) should it have?)

  2. Write a function to compute the area of a circle.  (What input parameter(s) should it have?)

  3. Write a function to compute the area of a ring.  (What input parameter(s) should it have?)


© Dung X. Nguyen

Last revised 08/24/2008 09:03 PM

Maintained by the professor; see contact information on the course home page