From leavens@larch.cs.iastate.edu Wed Mar 30 22:09:45 2005 Date: Wed, 30 Mar 2005 22:09:45 -0600 (CST) From: Gary T. Leavens To: Matthew J. Ring Cc: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: Re: Hw9, question 4 Hi Matt, On Wed, 30 Mar 2005, Matthew J. Ring wrote: > Do we need to implement ref->expressed and expressed->ref for this problem? > (All tests have passed without implementing above). They are needed only for full credit, as they have to do with type checking. > If so, I'm having > difficulty writing expressed->ref. > > I have the following: > > (define expressed->ref > (expressed-value:extract reference? "ref")) > > But my "reference?" is not identified and I'm not sure what else to put > there. You should use (lambda (x) ((ref-of expval?) x)) where you are trying to put reference? The ref-of procedure is provided by the module, but reference? isn't. 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 11 14:04:46 2005 Date: Mon, 11 Apr 2005 14:04:46 -0500 (CDT) From: Gary T. Leavens To: Com S 342 , Com S 342 TAs -- Brian Patterson , Daniel Patanroi , kuang-yao Lee Subject: Correction to problem 10 on homework 9 for 342 Hi all, Sayan Ranu pointed out that the description in the textbook (in exercise 3.55) of the call by value-result mechanism prohibits passing anything but a variable as an actual parameter to a procedure. However, one of the test cases we provided does pass a general expression that is not a variable as an actual parameter. To resolve this inconsistency, I have changed the description of problem 10 in homework 9 to allow actual parameters that are not variable references. This is consistent with what we did for call by reference, and matches most real languages better. Here's the revised first paragraph of that problem statement. Do exercise 3.55 on page 114 of the text. However, as with call by reference, we won't consider it an error to pass an expression as an argument; instead we will assume that a new location (i.e., a direct target) is created to hold such arguments, and thus a call such as (f add1(c)) will copy the value of add1(c) into the formal, but the actual will be copied back to this new location instead of into any previously existing variable's location (i.e., the variable c won't be affected). Sorry about this late change. To make up for it, here are a few more hints for doing problem 10. You shouldn't need to change the interface to apply-procval. In my solution it still is declared with the following type: (deftype apply-procval (-> (procval (list-of target)) Expressed-Value)) it may be helpful to think about how assignment works in the interpreter. You can think of call by value-result as first creating new locations (targets) for the formal parameters, assigning the actuals to the formals, running the body, and then assigning the formals back to the actuals. 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 Tue Apr 12 13:40:35 2005 Date: Tue, 12 Apr 2005 13:40:34 -0500 (CDT) From: Gary T. Leavens To: Com S 342 TAs -- Brian Patterson , Daniel Patanroi Subject: More about call by value result Hi Guys, Here's something I told several students about the call-by-value-result problem. Imagine a procedure p = proc(x,y) E and a call (p a b) The effect in call by value-result is similar to the code that would be executed in the call by reference interpreter for: let x = a % passing values y = b in let val = E % executing the body in begin set a = x; % copying results back set b = y; val % returning the value of the body end So students should think about what let does in the call by reference interpreter and about what assginment expressions do in that interpreter. 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 -------------------------