Fundamentals of CS I (CS151 2001S)

[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
**Primary**

[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
**Sets**

[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
**Links**

a. Scan through the reading
on procedures that retun multiple values. Make sure you understand
the standard Scheme procedures `values`

and
`call-with-values`

.

b. Start DrScheme.

`mixed-number-parts`

What are the results of applying `mixed-number-parts`

to
each of the following values? Explain each result.

- 17/5
- 4/7
- 40/2
- -2/5
- -10/3
- 1.3
- -0.5

a. What do you expect to happen when you add 2 to the result of
`(mixed-number parts 7/5)`

? Try it and see.

b. What do you expect to happen when you take the car of the result
of `(mixed-number parts 7/5)`

? Try it and see.

Using `call-with-values`

and `mixed-number-parts`

,
write `(whole-part `

, which gives the whole part
of a rational number, and *rat*)`(frac-part `

, which
gives the fractional part.
*rat*)

Write the `(divide `

procedure mentioned in the reading. Your procedure should return
two values: (1) a number, *dividend* *divisor*)*q*, such that *q***divisor* is less
than or equal to dividend and *(q+1)***divisor* is greater
than dividend; (2) the remainder.

Hint: Think about the strategy used in `mixed-number-parts`

.

Define and test a procedure `tallies-by-parity`

that takes any
list of integers as its argument and returns two values, the number of even
integers in the list and the number of odd integers in the list.

Hint: Use tail recursion.

You may not use `partition`

in your solution.

a. Solve the problem without using `call-with-values`

.

b. Solve the problem with `call-with-values`

.

Define and test a recursive procedure that takes an association list
`als`

as argument and returns two results: a list of the keys of
`als`

, and a list of the values of `als`

.

Fall 2000 [Samuel A. Rebelsky]

- Created. All of the problems were extracted from
`http://www.math.grin.edu/~stone/courses/scheme/multiple-valued-procedures.xhtml`

(Dated April 3, 2000). - Some updates to the phrasing of problems.
- Reformatted.
- Named problems.
- This version is available as
`http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/multivalue-proc.html`

.

Friday, 13 April 2001 [Samuel A. Rebelsky]

- Reformatted.
- Added history.
- Added 2b (car of values).
- Added
`divide`

exercise. - Added separating parts exercise.
- This version is available as
`http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/multivalue-proc.html`

.

[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
**Primary**

[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
**Sets**

[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
**Links**

**Disclaimer**:
I usually create these pages on the fly. This means that they
are rarely proofread and may contain bad grammar and incorrect details.
It also means that I may update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Thu May 3 23:07:54 2001.

This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/multivalue-proc.html`

.

You may validate
this page's HTML.

The source was last modified Fri Apr 13 08:43:15 2001.