From leavens@cs.iastate.edu Sat Apr 17 20:33:17 2004 Date: Sat, 17 Apr 2004 20:32:52 -0500 (CDT) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Ref Question Hi Jason, On Sat, 17 Apr 2004, Jason Cook wrote: > > Hi Jason, > > > > On Sat, 17 Apr 2004, Jason Cook wrote: > > > > > I am not quite sure what the ref-exp is supposed to do. There is > > > only one example in the book and I am not entirely sure what it is > > > doing. Can you explain this error to me, perhaps that would help > > > as well. > > > > The ref-exp is supposed to return a reference (pointer essentially) to > > a variable. It's like the C++ & operator. ... > I am not quite sure how to use a-ref. For example, it takes a > position and a vector, but neither of those types are available for > use in eval-expression. I thought about using a cases and tried > that, but it gave me an error saying it didn't know what a > reference was I believe. Do I need to add the reference define- > datatype? No, there is one already used by the envrionment datatype. The reference datatype is defined in 3-7-reference.scm, and should be loaded in your solution by leaving in the line: (load-quietly-from-lib "3-7-reference.scm") that appears in 3-7.scm, which you copied to start Scheme. References are made by extend-env, since they can be obtained by calling apply-env-ref. > I thought that if we needed that, it would be stated in > the problem. Right. > Could you give an example that uses a-ref to make a reference, or > would that be too similar and give the answer away? Yes, here you go... typed> (load-quietly-from-lib "3-7.scm") typed> (define my-vec (vector 15 0)) my-vec : (vector-of number) typed> my-vec #(15 0) : (vector-of number) typed> (define my-ref (a-ref 0 my-vec)) my-ref : (ref-of number) typed> (deref my-ref) 15 : number typed> (setref! my-ref 99) # : void typed> (deref my-ref) 99 : number Normally, however, you would obtain references using apply-env-ref.... typed> (define my-env (extend-env '(x y) (map number->expressed '(3 15)) (empty-env))) my-env : environment typed> my-env (extended-env-record (x y) #(3 15) (empty-env-record)) : environment typed> (apply-env-ref my-env 'x) (a-ref 0 #(3 15)) : (ref-of expressed-value) -- 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@cs.iastate.edu Mon Apr 19 09:25:04 2004 Date: Mon, 19 Apr 2004 09:24:25 -0500 (CDT) From: Gary T. Leavens To: Eric Douglas Nath Cc: cs342s@cs.iastate.edu Subject: Re: strange question about hw7 Hi Eric, On Sun, 18 Apr 2004, Eric Douglas Nath wrote: > Hey, I just had a strange question... I thought I understood the logic of the > makemult problem shown in the book on page 89, but I guess I don't really. I > got the first problem in hw 7 done, but going back and looking over it, I am not > sure what is going on, or at least I can't see how it works. > > Do you think one of you could quickly explain how it works? I sort of see that > something is calling itself, and acting like recursion, but I want to make sure > I get it. Well, that is a difficult thing to understand. Essentially, the idea is that makemult is a generator of multiplication procedures; when called, it generates a multiplication procedure. It takes as an argument a generator of multiplication procedures, of course, so that recursive calls can find some generator to call when needed. The idea results from abstracting out recursions by making them parameters. It's pretty tricky. For a better understanding of such things, see the last several chapters of the Little Schemer book. They have a patient explanation of the idea in the general case (the Y combinator). -- 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@cs.iastate.edu Wed Apr 21 20:47:51 2004 Date: Wed, 21 Apr 2004 20:47:35 -0500 (CDT) From: Gary T. Leavens To: Brian Wicks Cc: Computer Science 342 Staff Subject: Re: Homework 8 problem 3 Hi Brian, On Wed, 21 Apr 2004, Brian Wicks wrote: > I am getting an error - > Error: variable ref-of is not bound > > What might cause this? Are you working at home or not on the department machines? If so, the probelm is probably that you have an old copy of the library. Specifically, ref-of is defined in 3-7-reference.scm. The current version starts: ;;; $Id: 3-7-reference.scm,v 1.2 2004/04/17 00:53:15 leavens Exp $ If your library is out of date, then either fetch that file or the whole library (probably better) from the course library web page. -- 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@cs.iastate.edu Wed Apr 21 20:51:06 2004 Date: Wed, 21 Apr 2004 20:50:51 -0500 (CDT) From: Gary T. Leavens To: Jason C Kobes Cc: Computer Science 342 Staff Subject: Re: Final Hi Jason, On Wed, 21 Apr 2004, Jason C Kobes wrote: > I was interested in getting an early start on study for the final. which > exam from the previous would be a good example of what to expect? Thanks > again for all the help since the second exam, it has made the difference. Exam 4 from 2001 may be the closest. See: http://www.cs.iastate.edu/~cs342/old-exams/Fall01/exam4.pdf Although we have one more homework vs. that year, so more on chapter 3 of EOPL will be on our final. I will be making a study guide next week. -- 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@cs.iastate.edu Wed Apr 21 22:44:25 2004 Date: Wed, 21 Apr 2004 22:44:11 -0500 (CDT) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: HW8 #4b Hi Jacob, On Wed, 21 Apr 2004, Jacob Lynch wrote: > The question is, "What are the expressed and denoted values of this > language?" I'm not sure what they mean by this. Do they mean the > definition on the previous page? > > Expressed Value = Number+ProcVal+Ref(Expressed Value) > > Denoted Value = Expressed Value > > Or are they talking about this specific example? Or maybe something else? > Thanks for any help! The question refers to the language of the problem (i.e., 3.43 on p. 105). It would be something like the one on p. 104, but I would rather not say whether that is right or not. But I can say that: - The domain of expressed values refers to what may be returned by an expression. - The domain of denoted values refers to what may be bound to a name (hence denoted) in the environment. In all the interpreter source codes, there is a comment indicating these. You might want to start with the one in the 3-7 interpreter's sources. -- 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@cs.iastate.edu Thu Apr 22 11:05:44 2004 Date: Thu, 22 Apr 2004 11:05:32 -0500 (CDT) From: Gary T. Leavens To: Luan Chan Cc: cs342s@cs.iastate.edu Subject: Re: Question on Problem 3... Hi Luan, On Thu, 22 Apr 2004, Luan Chan wrote: > You mentioned to make it type check you have to change the data > type of apply-prim and primitive procedures to that of the one mentioned in > indirect-arrays.scm. To me it looks like you should be changed them to > (array-of Expressed-Value) . So I tried changing that and it still doesn't > type check. I'm not sure what I'm doing wrong. I said in problem 3: "You will have to change the define-datatype for primitive and the apply-primitive procedure. Use the ADT for arrays given in the indirect-arrays.scm file to make your code type check." The first sentence is confusing you, I think. My solution doesn't change the type of the apply-primitive procedure, just it's implementation code. The type of apply-primitive remains the same as in $PUB/lib/3-7.scm. Using the expressed values I gave you in $PUB/homework/hw8/my-3-7-expressed-value.scm will allow that to type check. Make sure you have your code loading your copy of that file instead of the normal library 3-7-expressed-value.scm, as that would cause a problem otherwise. -- 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@cs.iastate.edu Fri Apr 23 16:39:16 2004 Date: Fri, 23 Apr 2004 16:38:57 -0500 (CDT) From: Gary T. Leavens To: Eric Douglas Nath Cc: Computer Science 342 Staff Subject: Re: hw8 question.... Hi Eric, On Fri, 23 Apr 2004, Eric Douglas Nath wrote: > I don't know if this has been asked or addressed before, but I have a quick > question about hw8, number 3. > > when writing the arrayset-prim code, you use the array-set! function, which > returns void... how do I take that result and turn it into an expressed-value so > it will compile for apply-primitive? You have to use a begin expression in Scheme. In a Scheme expression of the form (begin E1 E2 ... EN E) the type checker checks that the types of the subexpressions E1, E2, ..., EN are void, and the type of the begin overall is the type of the last expression, E. For example, (begin (set! x 3) 0) has type number, as (set! x 3) has type void, and 0 has type number. -- 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 -----------------------------