Department of Computer Science and Engineering

CS 7100 Fall 2023                                                                                                                                  Prasad

Assignment 1 (NOT GRADED - Plan to complete by: October 3) 

1. Recursive Definitions 

EOPL 2nd ed. Text. Pages 26. Exercises 1:17: 1, 2, 3.

EOPL 3rd ed. Text. Pages 28. Exercises 1.29:, 1.30, 1.34.

2. Abstract Data Types

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 (Consult Java API description for larger context.)

  1. Specify the syntax and semantics of the ADT Map using algebraic (axiomatic) approach.
  2. Give an implementation of the ADT Map in Scheme.

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 develop?

Create well-documented solution 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).  Make sure that the solution files can be loaded and run in Racket without any modification. You must include test calls and expected results. 

You are encouraged to work in teams of two/three. Avoid the temptation of copying the solution from online or other sources. This will help you better prepare for the exam and for the rest of the course.

Sample "Well-documented" Definition

The following example is for Intermediate-Student language of Racket. The equivalent renditions for R5RS (Standard Scheme) are shown in asg1.ppt.

; 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:
, '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
(define (check-guess guess target)
             (cond [(> guess target) 'TooLarge ]
                   [(< guess target) 'TooSmall ]
                   [(= guess target) 'Perfect ]
;(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


... Map1
Reference: java.util.Map