Computer Science Fundamentals (CS153 2004S)

Homework 2: Type Checking

Assigned: Thursday, 29 January 2004
Due: 10:00 a.m., Wednesday, 4 February 2004
No extensions!

Summary: In this assignment, you will develop a procedure that computes the type of a Scheme value.

Purposes: To give experience writing procedures that use conditionals and recursion. To help you think further about Scheme's type system.

Collaboration: Although you may discuss this assignment with your colleagues, and even get help debugging, each student should write his or her own program. If you receive help from anyone, you should clearly document that help.

Helpful References:

Turning it in: Email me your answers.

Assignment

You have learned a number of types in Scheme already, including lists, procedures, Boolean values, symbolic values, and a host of numeric types. Many Scheme programmers, but particularly beginning Scheme programmers, benefit from learning the type of a value.

Write and test a Scheme procedure, type, that returns the a symbol that represents the narrowest possible interpretation of the type of its argument. If the argument is a list, you should determine if all the component values are the same basic type. If so, return the symbol list-of-type. If not, return heterogeneous-list. Classify exact non-integer real and rational numbers as rational. Classify inexact non-integer real and rational numbers as real.

For example,

> (type 3)
integer
> (type 3.0)
real
> (type 3.5)
real
> (type 7/2)
rational
> (type (list 1 2 3))
list-of-integer
> (type 'one)
symbol
> (type (list 'one))
list-of-symbol
> (type (list 1 'one))
heterogeneous-list
> (type "hello")
string
> (type 'type)
symbol
> (type type)
procedure

 

History

Wednesday, 28 January 2004 [Samuel A. Rebelsky]

 

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 Fri May 7 09:44:06 2004.
The source to the document was last modified on Wed Jan 28 20:45:48 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Homework/hw.02.html.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu