Lab Module E -- Data Abstraction

CISC 280 Program Development Techniques

Purpose:
  1. To learn some basic concepts of data abstraction.
  2. To use and manipulate Scheme's basic data structure.
Goals:
  1. To write procedures that use data abstraction
  2. To be able to write procedures that use cons, car & cdr to access data elements.

Reading: SICP (Structure and Interpretation of Computer Programs), Section 2.1

Homework exercises (Due at start of lab 11 March 01):

  1. SICP Exercise 2.7

  2. SICP Exercise 2.10
    In this exercise, you can make use of Scheme's error function. The syntax is

    (error "Print some error message" irritant)

    where the irritant is whatever is causing the problem.
    Example:
    (define (divide x y)
        (cond ((= y 0) (error "Trying to divide by" y))
    	  (else (/ x y))))
    

    Now the interpreter will give this result:
    >(define a (divide 3 0))
    Trying to divide by 0
    >a
    reference to undefined identifier: a
    
    We see that the error function terminates the program if encounterd, so that a is never defined to any value because (divide 3 0) failed. The irritant is optional, and when left out, error will just print the error message and terminate the program.
    Be sure to hand in several test cases. In some of the test cases, the interval should span zero and in some it should not.

  3. SICP Exercise 2.12

Flourishes (these are optional problems):

  1. SICP Exercise 2.1

  2. Using display define a functionprint-complex-numbers that prints complex numbers. You will have to make the constructor make-complex-number and the selectors real-part, and imag-part.
     
    (define x (make-complex-number 1 3))
    (real-part x)
    1
    
    (imag-part x)
    3
    
    (print-complex-number x)
    1 + i3
    
    Remember complex numbers are in the form real-part + i imag-part.

  3. Make functions add-complex-numbers, subtract-complex-numbers, and multiply-complex-numbers that add, subtract, and multiply complex numbers.