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]
a. Scan through the reading
on procedures that return 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.
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 rat)
, which gives the whole part
of a rational number, and (frac-part rat)
, which
gives the fractional part.
Write a non-recursive version of the (divide dividend
divisor)
procedure mentioned in the reading. Your procedure
should return two values, a quotient, quot, and a remainder,
rem. You should ensure that
You can use Scheme's built-in division operation or the quotient
and remainder
procedures in writing your answer.
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]
http://www.math.grin.edu/~stone/courses/scheme/multiple-valued-procedures.xhtml
(Dated April 3, 2000). That page has now been moved to
http://www.math.grin.edu/~stone/courses/scheme/spring-2000/multiple-valued-procedures.xhtml
.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/multivalue-proc.html
.
Friday, 13 April 2001 [Samuel A. Rebelsky]
divide
exercise.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/multivalue-proc.html
.
Thursday, 14 November 2002 [Samuel A. Rebelsky]
divide
exercise slightly.
For those with extra timesection.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/multivalue-proc.html
.
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:19:06 2002.
The source to the document was last modified on Thu Nov 14 14:54:45 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/multivalue-proc.html
.
You may wish to validate this document's HTML ; ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu