From smshaner@cs.iastate.edu Thu Oct 26 16:26:47 2006 Date: Thu, 26 Oct 2006 16:26:43 -0500 From: Steve Shaner To: cs342@cs.iastate.edu Cc: Gary T. Leavens Subject: CS 342: "let" semantics don't change in dynamic scoping Those students who debated the semantics of "let" had the right idea: I was wrong when I said that changes to the stack remained only until the end of a procedure application. This means that the expression let a = 3 in let p = proc() +(x, a) f = proc(x, y) *((p), y) a = 5 in *(a, (f let a = 2 in a 1)) starts with the stack-expression pair _____ a | |-> 3 exp: "let p = proc() +(x, a) f = proc(x, y) *((p), y) a = 5 in *(a, (f let a = 2 in a 1))" [after evaluating the first let- exp] and evolves to the pair _____ a | |-> 3 p | |-> (ProcText with ids: () and body: "+(x, a)") f | |-> (ProcText with ids: (x y) and body: "*((p), y)") a | |-> 5 exp: "*(a, (f let a = 2 in a 1))" [after evaluating the remaining outer let-exp's] From there, however, the binding of a to 2 (in the innermost let- exp) is around only long enough for the app-exp of f to have a first parameter with value 2. That is, we add it to the stack... _____ a | |-> 3 p | |-> (ProcText with ids: () and body: "+(x, a)") f | |-> (ProcText with ids: (x y) and body: "*((p), y)") a | |-> 5 a | |-> 2 exp: B="a" [remembering the context left to evaluate: "*(a, (f B 1))"] evaluate variable "a" using that environment & bind f's formal parameters (from it's ProcText) before evaluating f's body... _____ a | |-> 3 p | |-> (ProcText with ids: () and body: "+(x, a)") f | |-> (ProcText with ids: (x y) and body: "*((p), y)") a | |-> 5 x | |-> 2 y | |-> 1 exp: C="*((p), y)" [remembering the context left to evaluate: "*(a, C)"] ... then following execution of (p) as in-class (though note the difference in stacks!) to eventually arrive at the answer of: => D="+(x, a)" [same stack, remembering the context left to evaluate: "*(a, *(D, y))"] => D="+(2, 5)" [remembering the context left to evaluate: "*(a, * (D, y))"] => "*(a, *(+(2, 5), y))" [putting D in context] => "*(a, *(7, y))" [applying the add-primitive, exiting procedure "p" without changing the stack] => "*(a, *(7, 1))" [looking up variable "y" in the environment] => "*(a, 7)" [applying times-primitive, exiting procedure "f" and popping x, y off the stack] => "*(5, 7)" [looking up variable "y" in the environment] => "35" [applying times-primitive] So the result is 35, and the remaining elements on the stack leave scope as we resolve the outer let-exp's that created those bindings in the first place. Even though this e-mail is already quite long, let me wrap up with the following. I apologize for the misdirection and confusion during lecture today. This e-mail applies dynamic scoping correctly and should make your solution to problem 9 much simpler than what I was suggesting during lecture today. Doing so will have the nice side- effect of also passing all of the tests for problem 9. :) -Steve Shaner ------------------------------------------------------ From smshaner@cs.iastate.edu Sun Oct 29 14:41:25 2006 Date: Sun, 29 Oct 2006 14:41:24 -0600 From: Steve Shaner To: mroberts@cs.iastate.edu Cc: Gary T. Leavens Subject: Re: Homework 8 problem 4 On Oct 29, 2006, at 1:52 PM, mroberts@cs.iastate.edu wrote: > I noticed that problem four is listed in the assignment like a > normal assigned > problem, but no due date is given for it. Is problem 4 intended to > be an > assigned problem or a suggested practice problem? Good catch. It's actually supposed to be an extra-credit problem, worth 25 extra-credit points. We'll correct that in the hw8.txt shortly. -Steve Shaner ------------------------------------------------------ From leavens@larch.cs.iastate.edu Mon Oct 30 20:39:24 2006 Date: Mon, 30 Oct 2006 20:39:23 -0600 (CST) From: Gary T. Leavens To: Adam M Weber Cc: Steve Shaner Subject: Re: hw8 question 6 Hi Adam, On Mon, 30 Oct 2006, Adam M Weber wrote: > For this question are we supposed to just simplify until execution reaches p > or just show > > ___________ > X | | --> 3 > Y | | --> 5 > P | | --> (ProcText with ids (i, k) and body (list x, y, i, k)) > > > I guess what i am asking is there supposed to be more to this? Yes, there is supposed to be more than that. You should draw the stack at the point where execution reaches the *body* of p, not to the point where the execution reaches the let that declares p. 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 Oct 30 20:43:30 2006 Date: Mon, 30 Oct 2006 20:43:30 -0600 (CST) From: Gary T. Leavens To: Adam M Weber Cc: Steve Shaner Subject: Re: hw question 8 Hi Adam, On Mon, 30 Oct 2006, Adam M Weber wrote: > What are the text procedure and the apply-proctext? > > For the apply-proctext is that just going to do the eval-expression stuff. > > I guess I just don't understand what the text procedure is for? Both of these are for the "ProcText" ADT that is found in the file $PUB/homework/hw8/my-3-5-dynamic.scm. The text procedure is the constructor of the type, and the apply-proctext procedure is the observer. See line 172 of the file $PUB/homework/hw8/my-3-5-dynamic.scm. This is an instance of a procedural representation of an ADT. Does that help? 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 Nov 12 21:12:56 2006 Date: Sun, 12 Nov 2006 21:12:56 -0600 (CST) From: Gary T. Leavens To: whoffa@cs.iastate.edu Cc: Steve Shaner Subject: Re: Exam 3 Question Hi William, On Sun, 12 Nov 2006 whoffa@cs.iastate.edu wrote: > I can see from your Exams Page (http://www.cs.iastate.edu/~cs342/exams.shtml) > that you made some notes about the second exam study guide. I was wondering if > there were any notes about the exam 3 study guide that may be of use? Thanks for pointing this out. I forgot to edit the exams page earlier. The study guide has been there for a while, but only linked from the news. (Are you reading the news for the course?) 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 Nov 13 23:14:37 2006 Date: Mon, 13 Nov 2006 23:14:37 -0600 (CST) From: Gary T. Leavens To: Matt Miller Cc: Steve Shaner Subject: Re: Test Question 4 from Spring 2006 Hi Matt, On Mon, 13 Nov 2006, Matt Miller wrote: > I simply cannot do Question 4 from the sample exam of Spring 2006. I > thought I understood how these things worked, but I have been thinking about > this for 1.7 hours and have made 0% progress. I am missing something > fundamental. Is there a way I can get a 2 - 4 sentence answer about how to > solve this problem? I don't even need the code. I just want to be pointed > in the right direction (I want some key terms I can look up in the index of > the textbook and read about, because I obviously have some kind of knowledge > gap). The key to solving this is to make a closure be the value, in the initial environment of the symbol id. This closure is the one that would be made by the interpreter for proc (x) x. See section 3.5 in the text. You can test your solution using ch3-5.scm. 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 ------------------------