Directions: Submit a typed, stapled hard copy with your name(s), section(s), and the answers to each of the questions below.
Update 31 March: Question 5 updated with sample box and arrow diagrams
(* ML version *) val whale = {name="Orca", length=24}; my_function(whale); // --- PROGRAM POINT A --- // C++ version struct Whale { char * name; int length; }; Whale * whale = new Whale; whale->name = "Orca"; whale->length = 24; my_function(whale); // --- PROGRAM POINT B ---
char * concat(char * first, char * second); // defined elsewhere struct Whale { char * name; int length; }; Whale * whale = new Whale; whale->name = "Orca"; whale->length = 24; Whale * big_whale = new Whale; big_whale->name = concat("Big ", whale->name); big_whale->length = whale->length * 2;
whale
and big_whale
.struct Whale { char * name; int length; }; Whale * whale = new Whale; whale->name = "Orca"; whale->length = 24; whale->length = whale->length + 10; // Whale grows
class IntList { public: IntList(int head, IntList * tail); int hd(); IntList * tl(); bool null(); private: // ... etc. };
list
built-in data type.IntList * otter = new IntList(3, new IntList(4, new IntList(5, NULL))); IntList * sea_otter = otter->tl(); IntList * river_otter = new IntList(2, sea_otter);
IntList
class) that has the
same effect:val walrus = 30 :: 40 :: 50 :: nil; val seal = 10 :: 20 :: walrus; val porpoise = hd(seal) :: tl(walrus);
val kelp = [1,2,3]; val seaweed = tl(kelp); val algae = 5 :: 6 :: seaweed;
val urchin = { greetings=["hi","hello","howdy"], days=365, birthday=("February",29,2000) }; val anemone = #greetings(urchin); val starfish = (hd(anemone), "there");
val a = 1; val b = a :: [2]; val c = (b, "foo", ("hello", "world", ["bye"], tl(b))); val d = #4(#3(c));
The most recent version of this document can be found online at the following URL:
http://www.cs.washington.edu/education/courses/cse341/01sp/homework/hw1.html