Fundamentals of Computer Science I (CSC-151.02 2000F)

Class 18: Side effects, sequencing, and output

Back to Vectors. On to Scheme without DrScheme.

Held Monday, September 25, 2000


Today we visit issues pertaining to procedures that may behave differently each time you run them.



Impure Functions

Exercise 1: Rolling Two Dice

a. Define a procedure, (roll), that simulates a die. It should return a number between 1 and 6.

b. Define a procedure, (pair-a-dice), that produces the result of rolling two dice.

c. Define a procedure, (count-sevens num-rolls) that counts the number of sevens in the given number of rolls of a pair of dice dice.

d. Define a procedure, (sevens-or-elevens) that rolls two dice and returns true if they sum to seven and false otherwise.

Side Effects

Exercise 2. Simple Testing

Play with those three methods and see how they are similar and how they differ.

Sequencing Statements

Exercise 3: Playing with Sequences

a. Make sure that do-some-stuff works.

b. What do you think will happen if you try

(list (do-some-stuff))

c. Try some other simple sequences of operations.

Reading Input

Exercise 4: Computing Multiple Square Roots

a. Test this pair of procedures.

b. Make the pair of procedures repeatedly ask for a value and compute its square root. (Hint: use recursion.)

c. How do you stop your program?

d. Add a test that ensures that the value entered is a number and, if not, stops the program.


Thursday, 24 August 2000

Monday, 25 September 2000

Back to Vectors. On to Scheme without DrScheme.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at

Source text last modified Mon Sep 25 10:50:38 2000.

This page generated on Mon Sep 25 10:52:48 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at