Fundamentals of CS I (CS151 2002F)

**Primary:**
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]

**Groupings:**
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]

**ECA:**
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]

**Miscellaenous:**
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]

You may also want to keep the corresponding reading at hand.

- Exercises
- Exercise 0: Preparation
- Exercise 1: Square Roots
- Exercise 2: Simple Subtraction
- Exercise 3: Simple Multiplication
- Exercise 4: Extended Addition
- Exercise 5: Absolute Value
- Exercise 6: Exponentiation
- Exercise 7. Normal Mathematical Notation
- Exercise 8: Simple Definitions
- Exercise 9: The Definitions Pane
- Exercise 10: Saving Files
- Exercise 11: Reloading Files
- Exercise 12: Wrapup

- Notes

Start DrScheme and make sure that you're in full scheme mode. You may want to read the DrScheme lab to make sure you understand DrScheme.

a. Convince DrScheme to compute the square root of 137641.

b. Verify that the value that DrScheme returns is indeed the square root of 137641. (Try squaring the value DrScheme gives you by hand.)

Ask DrScheme to subtract 68343 from 81722.

Tell DrScheme to multiply 162 by 1383.

a. Ask DrScheme to add 3 and 4.

b. Ask DrScheme to add 3 and 4 and then add 5 to the result. You'll
need two calls to `+`

.

c. Ask DrScheme to add 3, 4, and 5 using only one call to `+`

.

d. What happens if you call the procedure `+`

with no arguments?
With only one?

Have DrScheme compute the absolute value of -197. You can use the
`abs`

procedure.

a. Ask DrScheme to compute the cube of 19 (that is, the result of
raising 19 to the power 3). You can use
`expt`

to compute
exponents.

b. Ask DrScheme to computer the nineteenth power of 3.

c. What do these results indicate about the relationship between procedures and arguments in Scheme?

Type each of the following expressions at the Scheme prompt and see what reaction you get.

`(2 + 3)`

`7 * 9`

`sqrt(49)`

You may wish to read the notes on this problem for an explanation of the results that you get.

a. Write a definition that will cause Scheme to recognize `dozen`

as a name for the number 12.

b. Write a definition that will cause Scheme to recognize
`raise-to-power`

as a synonym for `expt`

.

c. Use both names in expressions to verify that Scheme has understood them.

Copy the definitions you wrote for the preceding two exercises into the definitions pane and execute them.

Save the definitions that you copied into the definitions pane in
the previous exercise in a file named `beginning-scheme.ss`

.
(Conventionally, the names of files containing Scheme programs end in
`.ss`

.)

a. Quit and restart DrScheme.

b. Determine whether `dozen`

is still defined. (It shouldn't be.)

c. See if you can figure out how to get DrScheme to reload your saved definitions.

Quit DrScheme and log out of the workstation.

(2 + 3)

When DrScheme sees the left parenthesis at the beginning of the expression
`(2 + 3)`

, it expects the expression to be a procedure call, and
it expects the procedure to be identified right after the left parenthesis.
But `2`

does not identify a procedure; it stands for a number.
(A procedure application

is the same thing as a procedure call.)

7 * 9

In the absence of parentheses, DrScheme sees `7 * 9`

as three
separate and unrelated expressions -- the numeral `7`

;
`*`

, a name for the primitive multiplication procedure; and
`9`

, another numeral. It interprets each of these as a command
to evaluate an expression: ``Compute the value of the numeral
`7`

! Find out what the name `*`

stands for! Compute
the value of the numeral `9`

!'' So it performs the first of
these commands and displays `7`

; then it carries out the second
command, reporting that `*`

is the name of the primitive
procedure `*`

; and finally it carries out the third command and
displays the result, `9`

. This behavior is confusing, but it's
strictly logical if you look at it from the computer's point of view
(remembering, of course, that the computer has absolutely no common sense).

sqrt(49)

As in the preceding case, DrScheme sees `sqrt(49)`

as two
separate commands: `sqrt`

means ``Find out what
`sqrt`

is!'' and `(49)`

means ``Call the procedure
`49`

, with no arguments!'' DrScheme responds to the first
command by reporting that `sqrt`

is the primitive procedure for
computing square roots and to the second by pointing out that the number
`49`

is not a procedure.

August 23, 1997 [John David Stone]

- Created

March 17, 2000 [John David Stone]

- Last revised

29 August 2000 [Samuel A. Rebelsky]

- Separated from narrative by Sam Rebelsky
- Added a few problems and rearranged.

30 August 2000 [Samuel A. Rebelsky]

- Added loading problem.
- Added note about quitting.

Thursday, 25 January 2001 [Samuel A. Rebelsky]

- Added some links to procedure references.
- Added link to DrScheme lab.
- Updated formatting for new course.
- Added new problem dealing with different ways to call
`+`

.

Wednesday, 4 September 2002 [Samuel A. Rebelsky]

- Added links to the Glimmer Scheme reference.
- A few minor modifications to problems.

**Primary:**
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]

**Groupings:**
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]

**ECA:**
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]

**Miscellaenous:**
[Scheme Reference]
[CS151 2002F Gum]
[CS151 2001S]
[SamR]
[Glimmer Labs]
[schemers.org]

**Disclaimer**:
I usually create these pages on the fly

, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.

This document was generated by
Siteweaver on Mon Dec 2 09:18:40 2002.

The source to the document was last modified on Wed Sep 4 08:29:08 2002.

This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/beginning-scheme.html`

.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu