CS 784 Spring 2012 Prasad
EOPL 2nd ed. Text. Pages 26-27. Exercise 1.16: 1, 2, 4. Exercise 1.17: 1, 3.
EOPL 3rd ed. Text. Pages 27-29. Exercises 1.18, 1.26, 1.27. Exercises 1.30, 1.34.
We explore the relationship between algebraic (axiomatic) specification of a (generic) data type and its implementation. You are required to specify the ADT Map1 that supports the following operations described only informally here:
Note: The ADT specs are written in functional style and as such do not support assignments. For example, put(m,k,v) does not change the state of the existing map m. Instead, conceptually, it creates a new map by "cloning'' m and then modifying the copy by inserting the new k-v binding.
What to hand-in?
Submit your well-documented solutions to (i) problem 1 in defn.scm (containing Scheme functions including signature, test calls and outcomes (see Design Recipe and the sample given below)) and (ii) problem 2 in adt.scm (containing algebraic specs of the ADT as comments and a conforming implementation in Scheme) by executing the following turn-in command on unixapps1.wright.edu. (Make sure the solution files can be loaded and run in Racket without any modification.)
%/common/public/tkprasad/cs784/turnin-pa1 defn.scm adt.scm
Sample "Well-documented" Definition
; HtDP book Exercise 5.1.2
; Develop the function
check-guess
. It consumes two numbers,
guess
and
target
.
; Depending on how guess
relates to target
, the
function produces one of the following three answers:
,
;'TooSmall
'Perfect
, or
'TooLarge
.
; CONTRACT: check-guess : number number -> { TooSmall, Perfect, TooLarge }
; PURPOSE: check-guess takes two numbers - a guess and a target, and
; returns a symbol
TooSmall, Perfect or TooLarge
; depending on
whether target is more, equal or less than guess
; CODE:
(define (check-guess guess target)
(cond
[(> guess target) 'TooLarge ]
[(< guess target) 'TooSmall ]
[(= guess target) 'Perfect ]
)
)
; TEST CASES and EXPECTED OUTCOMES
;(in general, focus on boundary conditions and coverage)
(check-guess 3 5) "should be" 'TooSmall
(check-guess 5 5) "should be" 'Perfect
(check-guess 7 5) "should be" 'TooLarge