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.
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 the (divide dividend divisor)
procedure mentioned in the reading. Your procedure should return
two values: (1) a number, 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]
http://www.math.grin.edu/~stone/courses/scheme/multiple-valued-procedures.xhtml (Dated April 3, 2000).
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.
[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.