User Tools

Site Tools


assignments:a2

This is an old revision of the document!


Assignment 2

Download the file a2-money.zip in Assignments in the SVN. Instructions are in the PDF file W09-a2-money-spec.pdf.

Since your code will be executed and checked with a script, you must follow the instructions precisely. Your work is in a directory a2-money (with ecf file as is, in this folder). You must do a written report which you must include in this directory.

Before submitting, eclean and do a fresh compile and execute to make sure that you get a green bar. Then eclean the directory a2-money again (to get rid of the EIFGEN's) and submit it:

 submit -l 3311 a2 a2-money

Don't forget to also hand in your written report at the 3311 drop box in the CSE building.



void safety and HASH_TABLE [?G, ?K]

  • We would like to use HASH_TABLE[G, H] to implement the efficient version of MAP when we can rely on hashable keys.
  • Eiffelstudio 6.3 is in transition to implementing void safety (which means that the compiler will always catch errors of the type t.f(x) where t = Void). As part of the transition, a type with a question mark in front of it (?T) is detachable (allowed to be Void) whereas a type with an exclamation mark (!T) is an attached type (is never allowed to be void).
  • The latest version of HASH_TABLE inherits from TABLE [?G, ?K], i.e. the generic parameters are allowed to be attached to Void. So, to use HASH_TABLE in HASHABLE_MAP, we can proceed as follows:
class 
   HASHABLE_MAP [KEY -> {HASHABLE,COMPARABLE}, VAL]
inherit
   MAP[?KEY,?VAL] 
create
   make
feature 
   has (k: ?KEY):BOOLEAN  ...
 
   item alias "[]" (k: ?KEY): ?VAL assign override ...
 
   has_tuple(t: TUPLE[k:?KEY; v:?VAL]): BOOLEAN ...
 
   domain: ARRAY[?KEY]
 
feature{NONE}
   map_imp: HASH_TABLE[VAL, KEY]
end

The question mark will ensure that the keys and values can be Void. you may sometimes have to do the following to obtain a correct tuple type:

t: TUPLE[KEY,VAL]
 
t ?= [map_imp.key_for_iteration, map_imp.item_for_iteration]

“?=” is assignment attempt and is discussed in the text book OOSC2.

In the next version of EiffelStudio, the default will be that when you declare

t: T

t is attached. You will have to explicitly say

t: ?T

if you want to allow t = Void. It seems that the default in the future will be to move away from Void (and all those pesky “?” will disappear as well. The result will be that void safety will be checked at compile time rather than runtime (a huge improvement).

assignments/a2.1238645014.txt.gz · Last modified: 2009/04/02 04:03 by jonathan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki