MP4
CS603 Organization of Programming Languages
Due 18 April 2003

University of Alabama
Department of Computer Science
Spring 2003

Purpose

The purpose of this assignment is to do some $\mu$-Smalltalk programming.

Problem Description

Do problem 2 from the textbook. The definition of the elements of the Interval are incorrect. They should be $\{n, n + k, n + 2k, \ldots, m\}$ This means that you have to implement all of the methods in the superclass hierarchy of Interval which have subclassResponsibility self in them, e.g. firstKey. The template for Interval is:
(class Interval SequenceableCollection (n m k)
  (classMethod from:to: (from to) ... )
  (classMethod from:to:by: (from to by) ... )
  (method firstKey () ... )
  (method lastKey () ... )
  (method at:ifAbsent: (index exnBlock) ... )
  (method at:put: (key value) (error: self #can't-add-to-an-Interval))
  (method species () Interval)
  (method printName () (print #Interval))
  (method remove:ifAbsent: (oldObject exnBlock) 
        (error: self #can't-delete-from-an-Interval))
  (method associationsDo: (aBlock) ... )
)
And here is an example interaction:
-> (val myIntv (from:to: Interval 2 6))
Interval( 2 3 4 5 6 )
-> (firstKey myIntv)
1
-> (lastKey myIntv)
5
-> (at:put: myIntv -1 -1)
run-time error: can't-add-to-an-Interval
-> (do: myIntv (block (x) (begin (print #inDo:) (println x))))
inDo:2
inDo:3
inDo:4
inDo:5
inDo:6
nil
-> (species myIntv)
<class Interval>
-> (printName myIntv)
IntervalInterval
-> (remove:ifAbsent: myIntv 1 [(println #inAbsentBlock)])
run-time error: can't-delete-from-an-Interval
-> (associationsDo: myIntv 
    (block (association)    
      (begin (print (key association)) 
                   (print #:) 
             (println (value association)))))
1:2
2:3
3:4
4:5
5:6
nil
->

How to Turn in Your Program

Email the program file, Interval.smt to mailto:jones@cs.ua.edu?subject=CS603MP4jones@cs.ua.edu with a subject line of CS603MP4. If it all possible, try to send this from the email account you placed on the index card. In any case, be sure that your name is included in both program source files and in the body of your email message. Comments in $\mu$-smalltalk are written using a semi-colon:
; This is a comment
Be sure to follow the guidelines below:
  1. Method names must exactly match those in the assignment.
  2. The file name must be ``Interval.smt''
  3. All methods given in the template for Interval must be present.
  4. Your files must be completely syntactically correct. Your file, as handed in, must pass through the interpreter with no syntax errors.
  5. Your files should not contain test code or other code which produces unnecessary output. Keep your test code separate from the code you hand in.

About this document ...

MP4
CS603 Organization of Programming Languages
Due 18 April 2003

This document was generated using the LaTeX2HTML translator Version 2K.1beta (1.61)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 0 -nonavigation MP4.tex

The translation was initiated by on 2003-04-16


2003-04-16