From patterbj@cs.iastate.edu Wed Apr 20 19:02:19 2005 Date: Wed, 20 Apr 2005 19:02:18 -0500 From: Brian Patterson To: Adam Nelson Cc: cs342s@cs.iastate.edu Subject: Re: Homework 11 On Apr 20, 2005, at 6:54 PM, Adam Nelson wrote: > I'm working on question 4 and have one case that doesn't turn out > right still. > > > Test case of $Date: 2005/04/18 20:15:03 $ > > (run > "class c1 extends object\r\n method initialize () 1\r\n > class c2 extends c1\r\n method initialize () 1\r\n > class c3 > extends c2\r\n method initialize () 1\r\n let o1 = > new c1() > \r\n o2 = new c2()\r\n o3 = new c3()\r\n > in > list(instanceof o1 c1, instanceof o2 c1, instanceof o3 c1,\r\n > instanceof o1 c2, instanceof o2 c2, instanceof o3 c2,\r\n > instanceof o1 c3, instanceof o2 c3, instanceof o3 c3)") > ==> (1 1 0 0 1 1 0 0 1) > EXPECTED: (1 1 1 0 1 1 0 0 1) > > I'm guessing it's because it's checking to see if o3 is an instance of > c1. I > am currently using the code: > > ... > > Is there an easier way to do this, checking to see if the class still > has a super class before trying to check it? I tried adding a third level > to the or and got an error message, so I figured that I should check > to see if I'm missing something obvious. It looks like you need to recurse more than a single level. For example if c1 extends object, c2 extends c1, and c3 extends c2 so c3 is a c1 object but c2 is its superclass. You have a right idea for doing the problem - you just need to follow the hint and use recursion to investigate the inheritance hierarchy more. Brian ------------------------------ From patterbj@cs.iastate.edu Wed Apr 20 20:11:56 2005 Date: Wed, 20 Apr 2005 20:11:56 -0500 From: Brian Patterson To: Adam Nelson Cc: cs342s@cs.iastate.edu Subject: Re: Homework 11 On Apr 20, 2005, at 8:01 PM, Adam Nelson wrote: > Follow up question and a new one: > > How can I tell if the class has a super-class or not? 1. All classes except 'object have a superclass. At least in our defined language, all classes must inherit from something, even if it's just object. > > Also, when trying my fieldref and fieldset questions, I'm getting an > unusual > error. > list->vector: expects argument of type ; given (vector > (make- > number->expressed 0) (make-number->expressed 0)) > > The code I'm using for fieldref is: > ... > > I'm guessing that the lists from object->field-ids or object->fields > is for > some reason passing a vector instead of the list the type-def says it's > supposed to. I just downloaded the new course library before starting > on > this, so I know it's up-to-date. > 2. field-ids is a list (see classes define datatype) and the fields are stored as a vector (see object define datatype). Brian ----------------------------------- From leavens@larch.cs.iastate.edu Wed Apr 20 22:56:09 2005 Date: Wed, 20 Apr 2005 22:56:09 -0500 (CDT) From: Gary T. Leavens To: Kendra Schmid Cc: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: Re: 342: Print limited code? Hi Kendra, Yes, I talked with Brian Patterson who's grading this byy email, and he's fine with that. On Wed, 20 Apr 2005, Kendra Schmid wrote: > To print out the code for hw11 is 16 pages long for me. Would you consider > allowing us to only print out what we changed and show code in a similar > format to how exams work such as > deftype eval-expression (-> (expression environment) Expressed-Value)) > (define eval-expression > (lambda (exp env) > (cases expression exp > .... > > ))) > > I see the benefits to this as being easier for the TAs to grade (not having > to wade through pages to find the small sections of code) and fewer pages for > us to print. > Thanks for considering it, Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------ From leavens@larch.cs.iastate.edu Thu Apr 21 00:17:30 2005 Date: Thu, 21 Apr 2005 00:17:30 -0500 (CDT) From: Gary T. Leavens To: Matthew J. Ring Cc: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: Re: Hw11, q4 Hi Matt, On Thu, 21 Apr 2005, Matthew J. Ring wrote: > This is related to the posted e-mail on the Q & A on the web site. > > My code generates the same issue that the other student had: > > ... > > I'm not sure exactly how to recurse through the application, and not for > lack of trying. The following code was attempted, but it runs into an > infinite loop. > > ... > > I later realized that it is running an infinite loop because my object > expression always grabs the same class-name, not the parent class-name. It > is probably an obvious mistake, but I just don't see it right now. Right. What you need to do is recurse on the structure of subclasses as described in class. (See the code of find-method-and-apply in 5-4-1.scm, which is what we discussed.) The interpreter has information about the class structure accessed through symbols. What you should do is to use class-name->super-name to ascend the chain of superclasses, remembering that the class named object does not have a superclass. In the hints, I suggested writing a separate helping procedure to determine when one class is a subclass of another. That makes this recursion easier. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------- From leavens@larch.cs.iastate.edu Mon Apr 25 22:51:29 2005 Date: Mon, 25 Apr 2005 22:51:28 -0500 (CDT) From: Gary T. Leavens To: Brice Lambi Cc: Brian Patterson , Daniel Patanroi Subject: Re: HW 11, Problem #6 Hi Brice, Yes, the modifiers are a new syntactic category associated with the nonterminal "modifier". we usually associate a new abstract data type with each nonterminal in the grammar. So I agree with Brian. On Mon, 25 Apr 2005, Brian Patterson wrote: > An ADT seems like the most direct way to me. > > Brian > > On Apr 25, 2005, at 6:03 PM, Brice Lambi wrote: > >> Hello, >> In order to add the syntax for modifiers are we supposed to use an ADT >> or is there some other way we are supposed to do that? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------- From leavens@larch.cs.iastate.edu Sun May 1 19:28:45 2005 Date: Sun, 1 May 2005 19:28:45 -0500 (CDT) From: Gary T. Leavens To: Sayan Ranu Cc: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: Re: question about parameter mechanisms Hi Sayan, On Sun, 1 May 2005, Sayan Ranu wrote: > I am not sure whether my solution to this is correct or not. can you please > check and let me know the correct answer is it's wrong > > letarray a[2]; b[2] > in let p = proc(x,y) begin > set y = b; > set x = 5 > end > in begin > set a[0] = 1; set a[1] = 2; > set b[0] = 4; set b[1] = 6; > (p a[1] a); > list(a[0],a[1],b[0],b[1]) > end > ------------------------------------------ > What does this do under call-by-value in the indirect model ? > ==> (1 2 4 6) > What does this do under call-by-reference in the indirect model? > ==> (4 6 4 6) > What does this do under call-by-value in the direct model? > ==> (1 2 4 6) > What does this do under call-by-reference in the direct model? > ==> (4 5 4 6) Yes, those are all correct. This is a nice problem, although it would give the same answer for call by name and call by need as with the call by reference cases. You might also want to try changing the body of p to distinguish these mechanisms more. For example, what happens if you pass b[1] instead of a[1] as an argument? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580