From leavens@larch.cs.iastate.edu Wed Apr 5 23:33:43 2006 Date: Wed, 5 Apr 2006 23:33:43 -0500 (CDT) From: Gary T. Leavens To: gqiu@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: exam questions Hi Grace, On Wed, 5 Apr 2006 gqiu@cs.iastate.edu wrote: > I have a couple of questions regarding the upcoming exam. First, on the Spring05 > exam, problem 1, it states that "quote" is a special form used. Does this imply > that item1, item2 are symbols and therefore neither bound or free? Yes it does. > Same going > for "f" (being neither bound or free since lambda is a special form)? Right. > Second, also in the Spring05 exam, you mentioned various times for our code to > "type check." Does this simply mean that say if the procedure returns an > environment, make sure it returns an environment? (problem 3) Or perhaps do an > > > (if (expressed->number? ...)) > > type of check? (problem 5) Both. In Spring 05 we hadn't made the Expressed-Value domain be a define-datatype, so type checking was different than getting things right. Now with Expressed-Value the way we have done it, they are synonymous, and so we haven't had to emphasize type checking as much. > Finally, I noticed that the Spring04 exam only had 4 problems as opposed to 7 > for Spring05. Am I correct in assuming our test is going to be more similar to > Spring05's in terms of content as well as the number of problems? Yes. 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 cshinatr@cs.iastate.edu Thu Apr 6 06:03:02 2006 Date: Thu, 6 Apr 2006 06:03:02 -0500 From: cshinatr@cs.iastate.edu To: Gary T. Leavens Subject: COMS 342: Exam 3 questions Hello, I have questions regarding today exam. S05 Question 4 Would the interpreter for the defined language be able to correctly implement statically-scoped let expression if eval-expression did not pass the environment to recursive calls? I think the answer is no since it~Rs a recursive calls, it would need to refer to the environment but I~Rm not sure if that is the answer for this. I also just wondering, this is the same for dynamically-scoped as well, right? --------- What is the importance of representation independence? And give example. --------- What does each of the procedures in the simple interpreter do? What is its type? --------- What are the difference b/w the defined language~Rs truth values and those of Scheme? I think the difference is that in defined language~Rs truth value is 1 but in Scheme it considers any nonzero value to be true. Do I understand this correctly? --------- Also, I~Rd like you to explain more about closure. For example, explain purpose of closures in the interpreter. How does the interpreter use them? Why it needed? How do they relate to static scoping? Are closures needed in a language that does not allow nested procedures? Thanks, Chontichar Shinatrakool ----------------------------------- From leavens@larch.cs.iastate.edu Sun Apr 9 14:26:32 2006 Date: Sun, 9 Apr 2006 14:26:32 -0500 (CDT) From: Gary T. Leavens To: Shinji Kawasaki Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: question about make array Hi Shinji, On Sun, 9 Apr 2006 kinta@cs.iastate.edu wrote: > Hi I am doing Question 3 of HW9 > > I have question of procedure make-array in indirect-arrays.scm > > (deftype make-array (forall (T) (-> (number) (array-of T)))) > > (define make-array > (lambda (size) > (make-vector size 0))) > > According to the deftype and define, It seems that we only need one argument for > this procedure. However when I try to execute this procedure with one argument > then error. > > (make-array 2) > procedure make-array: expects 2 arguments, given 1: 2 > > I am sure argument must be number, and this procedure generate vector which size > is respect argument and all element is "0". > > Why this error happen? I changed the library so that version 1.4 of indirect-arrays.scm has (deftype make-array (forall (T) (-> (number T) (array-of T)))) (define make-array (lambda (size val) (make-vector size val))) The library on the department machines has this. If you are working at home, you should update to get that version. 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 10 22:02:51 2006 Date: Mon, 10 Apr 2006 22:02:51 -0500 (CDT) From: Gary T. Leavens To: rmatus@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework 9, Problem 3 cont'd... Hi Rich, The elements of the arrays in the interpreter should be expressed values. That is the meaning of the domain equation: Arr = (Ref(Expressed-Value))* The error you are getting is from the array->expressed procedure. The define-datatype for Expressed-Value is as follows. (define-datatype Expressed-Value expval? (number->expressed (num number?)) (procval->expressed (pv procval?)) (list->expressed (lst (list-of expval?))) ;; added for exercise 3.42 + arraylen (array->expressed (arr (array-of expval?))) ;; added for exercise 3.43 (denoted->expressed (ref (ref-of expval?)))) This says that the arr field has to be an array of expressed values. The number 0 is not an expressed value, although (number->expressed 0) is. Is your question about "T" related to the type notation? If so, see the type notation page: http://www.cs.iastate.edu/~leavens/typedscm/ especially http://www.cs.iastate.edu/~leavens/typedscm/typedscm.html#SEC4 On Mon, 10 Apr 2006 rmatus@cs.iastate.edu wrote: > Hi... > > This line ... > > (array-prim () (array->expressed (make-array (expressed->number(car args)) > 0))) > > Causes this error... > > . array->expressed: bad value for arr field: (vector 0 0 0) > > I have an idea that it has to do with that T value in the indirect-arrays.scm > file... it's not a number, it's just... T... I don't get what T is supposed to > be... Datum? what? > > I think that's where it starts, but I don't know what value to put in to get it > to work. > > Rich > > 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 10 22:04:31 2006 Date: Mon, 10 Apr 2006 22:04:31 -0500 (CDT) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Hints for Problem 4... Hi Rich, On Mon, 10 Apr 2006 rmatus@cs.iastate.edu wrote: > Do you have any hints for problem 4? I'm not sure why you're showing us two > different ways of doing ref'ed values... we had all this done in class, and now > it seems like you're having us implement it in the interpreter in a totally > different way? No, it's not a new implementation. It's new langauge features. Try looking at the teset cases. 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 10 22:19:30 2006 Date: Mon, 10 Apr 2006 22:19:30 -0500 (CDT) From: Gary T. Leavens To: rmatus@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Hints for Problem 4... Hi Rich, On Mon, 10 Apr 2006 rmatus@cs.iastate.edu wrote: > Well, we already have a setref and a deref and all that that you gave us in > class on Tuesday... but now we're adding new ones again? Or are you saying the > code you gave us was the underlying material and we're adding the commands to > the interpreter to USE the code you wrote in class? The setref and deref were part of the reference ADT inside the interpreter. Problem 4 makes surface-level syntax, i.e., primitives, available to the programmers using the interpreter directly. Of course the implementation of these might use the ADT operations. > I figured out the primtive things in problem 3... you gave us documentation on > how the array commands were to be laid out... which ws different than the other > times you gave us primtives... so it made me think we had to set them up > differently. Sorry for the confusion. > Why are the add commands and many of those commands primtives and not just > expressions? couldn't you do the primitive commands in the expressions as > well? You could add them as expressions, but then you would end up duplicating some of the code that handles primitives. Essentially, if the new syntax evaluates all its arguments, then it can be added as a primitive. Note that the ref expression doesn't evaluate it's argument (the variable name), hence it gets added as an expression, not as a primitive. > I'm totally lost on what to do about the ref expression. I think I have the two > primtives set up, according to the primtive stuff from before, as well as using > the commands from reference-3-7.scm. > > how do you create a new ref? I'm sure ultimately that's what you want us to do > with the ref expression, but I have no clue how to do it. A defined language programmer create a new reference using the ref expression. In the interpreter you have to implement the ref expression using the constructor of the reference ADT (a-ref). 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 Wed Apr 12 18:10:38 2006 Date: Wed, 12 Apr 2006 18:10:37 -0500 (CDT) From: Gary T. Leavens To: Brian S. Cain Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework 9 Hi Brian, On Wed, 12 Apr 2006, Brian S. Cain wrote: > I am having problems with this problem 3 I believe it is. Speicifically the > array-set! and its void return type. I am not sure how to turn the void > into an expressed type . My initial though was to use a let statement to > have it initially run the procedure and then return (number->expressed 0) > > Am I on the correct track for this problem? Yes, that would work. You can also use begin in Scheme to do something and then return some other value. For example, (begin (set! x 3) 15) returns 15, not #. 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 Apr 16 23:14:25 2006 Date: Sun, 16 Apr 2006 23:14:25 -0500 (CDT) From: Gary T. Leavens To: rmatus@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework 9, problem 8... Hi Rich, On Sun, 16 Apr 2006 rmatus@cs.iastate.edu wrote: > Do you want this in direct, or indirect model? There are no arrays in this problem, so it doesn't matter much. But you can draw the integers as in the indirect model. 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 ---------------------- Hi Rich, On Mon, 17 Apr 2006 rmatus@cs.iastate.edu wrote: > I seem to be having trouble with problem #10. It will work for most of the > problems, but it gets stuck on three of them, and I'm coming to the conclusion > that it is going though it with call by value, but the value is destroyed when > the procedure finishes, thereby not allowing me to copy the value back out and > into the original place. > > I'm lost as for a reason, or a fix... Could you take a look at my code and give > a hint or a comment about it? When you are copying back to the actuals, you are making a new vector containing the actual arguments, and using setref! on a new reference you create with a-ref. That doesn't work. You have to use setref on the reference in any indirect-target contained in the target actual. 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 17 23:47:35 2006 Date: Mon, 17 Apr 2006 23:47:35 -0500 (CDT) From: Gary T. Leavens To: rmatus@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #9 Problem 10... Hi Rich, On Mon, 17 Apr 2006 rmatus@cs.iastate.edu wrote: > How do we get a reference? Setref requires one, and we're using targets > otherwise? There are references in indirect targets. If the target is not an indirect target, you can't change it anyway, this happens when you pass some non-variable as an argument. > How can we change the value in the copy back otherwise? You aren't changing it now. You change it by suing setref! on the right reference... 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 -------------------------