CSC 270 - Survey of Programming Languages: Scheme (Racket)

Varieties of Data

Varieties of Data

Mixing and Distinguishing Data

Predicates

Predicates for user-defined structures

Exercise

Redefining distance-to-0

Another example: Square and Circle

Finding the perimeter of a shape

Designing Programs for Mixed Data

Data Analysis and Design

Template

Body

Developing Data Representations

Changes in the Perimeter Program

;; perimeter : shape --> number
(define (perimeter a-shape)
 (cond
	[(circle? a-shape)(circ-perimeter a-shape)]
	[(square? a-shape) (sq-perimeter a-shape)]
	)
)
;; circ-perimeter : shape --> number
(define (circ-perimeter a-shape)
  (* (* (circle-radius a-shape) 2)pi))
;; sq-perimeter : shape --> number
(define (sq-perimeter a-shape)
  (* (square-length a-shape) 4))

Input Errors

Checking for Input Errors

[Back to the Notes Index]