From leavens@larch.cs.iastate.edu Sun Feb 12 20:49:47 2006 Date: Sun, 12 Feb 2006 20:49:47 -0600 (CST) From: Gary T. Leavens To: Nick Retzl Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS 342 problem 3, homework 4 Hi Nick, On Sat, 11 Feb 2006, Nick Retzl wrote: > I have a little confused with problem 3 on homework 4. I'm a little > confused on how to assign the p values or the q values to #t or #f. And I'm > also a little confused on how we're supposed to evaluate booleans with the > expressions from bexp-mod, but this may be cleared up if I understand better > what to do with the #t #f values that are supposed to be assigned to P and Q. > Thanks for the help. The P and Q variables only give values as arguments to beval. For example, (beval (parse-bexp 'P) #t #f) ==> #t (beval (parse-bexp 'Q) #t #f) ==> #f They aren't assigned to Scheme variables, but are just given values as part of the evaluation process that you are to implement in beval. That is, when beval's bexp argument is one for which var-exp? is true, and that var-exp's varref is on for which P? is true, the second argument to beval should be returned. Similarly for Q. As the problem states: "(beval bexp p-val q-val) returns the value for bexp when P has the value p-val and Q has the value q-val." 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 Feb 12 20:57:21 2006 Date: Sun, 12 Feb 2006 20:57:21 -0600 (CST) From: Gary T. Leavens To: Chris Cornelison Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS342 - HW4, problem 2 Hi Chris, On Sat, 11 Feb 2006, Chris Cornelison wrote: > In problem 2, can "map" be used in the horizontal? and vertical? cases, or do > we need to create helper functions, or are neither necessary? You can use map. > Because there is only one non-terminal, "Following the Grammar" seems to > imply no helpers. One production with multiple alteratives For Kleene star in a grammar it's fine to use map, I think I didn't explain that in class, but the handout does use it. See section 5.2.2 of the Following the Grammar handout (and Figure 4). > I think I have the correct outline and my base case works, but I can't see > how to do the recursion. > ... > What I have doesn't work because horizontal->subwindows returns a list-of wl, > and shrink-to takes a wl. Right. This is a good place to use map. A helping procedure as in your later e-mail is also fine and follows the grammar in that e-mail. > I not really trying to debug this code, but rather understand how to think > about this. > > Should I be able to write this procedure by only looking at the examples, or > do I have to understand the internals of the helper functions in > window-layout-mod.scm to solve this problem. You shouldn't need to understand the internals of the helper functions to solve this problem. > It seems like the general idea is that we have put in place a layer of > abstraction to save us from working with bare lists using cons, car, and cdr, > correct? Yes, that's the idea of the helping procedures. The other general idea is the basic outline and recursion structure for following the grammar, of 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 Sun Feb 12 21:08:41 2006 Date: Sun, 12 Feb 2006 21:08:41 -0600 (CST) From: Gary T. Leavens To: Corey J Mitchell Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: hw 4 #2 Hi Corey, On Sun, 12 Feb 2006, Corey J Mitchell wrote: > I am having trouble with the recursive calls on this problem. I know what I > need to do, I just don't know the syntax of how to do it. > I can't figure out how to do the mapping because map and apply take 2 > arguments, so i can't figure out the syntax of how to send it shrink-to with > the width and height arguments too. I have been on this for several hours. > Please help! See the second paragraph of section 5.2.2 in the following the grammar handout. Essentially this says that you have to use lambda to bridge such gaps. Since map needs a procedure of one argument as its first argument, use a procedure that looks like (lambda (wl) ...) but does what you want inside; not that the lambda-expression can refer to formal parameters of the surrounding procedure. 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 Feb 13 12:10:56 2006 Date: Mon, 13 Feb 2006 12:10:56 -0600 (CST) From: Gary T. Leavens To: Chris Cornelison Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS342 - HW4 typos? Hi Chris, On Mon, 13 Feb 2006, Chris Cornelison wrote: > Gary, > > In problem 7... > > Write a procedure > > all-ids : (-> (statement) (set-of symbol)) > > such that (all-varrefs stmt) returns .... > > "all-varrefs" ?? > > did you mean "all-ids" instead? Yes, thanks. I've fixed that now. 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 Feb 13 18:07:11 2006 Date: Mon, 13 Feb 2006 18:07:11 -0600 (CST) From: Gary T. Leavens To: bkshmidt@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: COMS 342 HW 4 Q#4 Hi Brian, On Mon, 13 Feb 2006 bkshmidt@cs.iastate.edu wrote: > Prof Leavens: > > I am having problems on Question number 4 of the homework. I can get the output > to be similar but not exact as it should be. For example, when I run: > > (bswap (var-exp (P))) > > I get: > > (var-exp Q) > > When I should get: > > (var-exp (Q)) That's actually fine. Notice the difference between examples with an arrow (==>) and an equals sign (=). Examples with an equals sign like (bswap (var-exp (P))) = (var-exp (Q)) means that both sides are Scheme expressions which both evaluate to the same thing (actually something equal? to what the other side evaluates to). If you evaluate the right hand side, you'll see that (var-exp (Q)) ==> (var-exp Q) That is, in the interpreter: > (var-exp (Q)) (var-exp Q) and since (var-exp Q) this is equal? to the value of the left hand side, you are fine. > I did not see anything in the code to declare an object a varref. Are the > parenthese around (Q) suppose to be there? The helping procedures P : (-> () varref) Q : (-> () varref) (and also parse-varref, which you shouldn't use) produce varrefs. In (P) and (Q) in your expressions, these are calls on the P and Q procedures, which take no arguments, and return the internal representation of a varref (which in the current implementation is a symbol). 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 Feb 13 21:25:34 2006 Date: Mon, 13 Feb 2006 21:25:34 -0600 (CST) From: Gary T. Leavens To: Brian S. Cain Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework 4 Hi Brian, On Mon, 13 Feb 2006, Brian S. Cain wrote: > While trying to do Homework Problem 3 and 4 tonight I was getting errors > that I don't think I should be getting. > > Specifically when I went to go and test my base case on problem 3 I got the > following error. > >> (beval (parse-bexp 'P) #t #f) > > . parse-varref: bad syntax: p > >> (parse-varref 'P) > > . parse-varref: bad syntax: p > This could be caused by the DrScheme settings. By default DrScheme is case sensitive, so that (eq? 'P 'p) ==> #f (contrary to R5RS). So I get: > (parse-bexp 'P) (var-exp P) > (parse-bexp 'p) . parse-varref: bad syntax: p with this setting. However, perhaps you have changed this setting by going to the "Language" menu, by selecting "Choose Language" and then "Show Details", and then unchecking the box at the right in "Input Syntax" that says "Case Sensitive"? If you do that, things break. A quick fix is to check the "Case Sensitive" box. In a minute I'll update the library lib342.zip, so that this isn't a problem, at least for bexp-mod.scm. > I did have to update the lib342.zip today because when I went to go start > the homework I was missing several files (specifically the file for problem > 2). I updated this and things started to go down hill from there. I have > been getting errors like this, as well as strange working of DrScheme. The > main problem that DrScheme seems to be having is the fact that it is now > consuming large amounts of processor time. It will boost my processor > useage up to 100% when I click on run to test my work. You may need to run "Setup PLT.exe" from the top of the PLT install directory again. > If you know what the problem is and how to fix it please let me know, other > wise I will plan on stopping by your office tomorrow at around 11:00 or so > to see if we can't get the problem solved. See above, let me know if that doesn't work. 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 Feb 14 22:10:45 2006 Date: Tue, 14 Feb 2006 22:10:45 -0600 (CST) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #4 Problem 8.... Hi Rich, On Tue, 14 Feb 2006 rmatus@cs.iastate.edu wrote: > Here is my problem... > > When I run this example... > > (subst-identifier 'x 'a > (set-stmt 'a (begin (list (set-stmt 'a (num-exp 3))) (var-exp 'b)))) > > > on my code (given below) when it gets to the set-stmt->exp call, it only pulls > the (var-exp 'b) segment from the code. It seems to completely ignore the > begin... as though it's not an expression? I'm not sure why... It seems like > the ( before begin would make everything the expression... In the above, you can't use "begin" to construct a begin-expression. What's happening is you're using the Scheme "begin" keyword. You want to use the helper for the statement-expression grammar "begin-exp" instead. Using Scheme's "begin" (set-stmt 'a (begin (list (set-stmt 'a (num-exp 3))) (var-exp 'b)))) evaluates to the same thing as (set-stmt 'a (var-exp 'b)) because in a Scheme begin of the form (begin (list ...) vb), the value of (list ...) is thrown away. 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 Feb 15 09:10:06 2006 Date: Wed, 15 Feb 2006 09:10:06 -0600 (CST) From: Gary T. Leavens To: Com S 342 , Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #4 Problem 8.... Hi all, Two examples in the text of problem 8 [subst-identifier] of Homework 4 have been corrected at 9:00am on Wednesday, Feb. 15. These were examples on lines 327-329 of hw4.txt. On those lines change the faulty (subst-identifier 'x 'a (set-stmt 'a (begin (list (set-stmt 'a (num-exp 3))) (var-exp 'b)))) = (set-stmt 'x (begin (list (set-stmt 'x (num-exp 3))) (var-exp 'b))) to the corrected: (subst-identifier 'x 'a (set-stmt 'a (begin-exp (list (set-stmt 'a (num-exp 3))) (var-exp 'b)))) = (set-stmt 'x (begin-exp (list (set-stmt 'x (num-exp 3))) (var-exp 'b))) Thanks to Rich Matus for pointing these out, and sorry for the confusion caused by the mistakes. 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 Feb 16 23:45:15 2006 Date: Thu, 16 Feb 2006 23:45:15 -0600 (CST) From: Gary T. Leavens To: Denise Bacher Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: hw4 problem 10 On Thu, 16 Feb 2006, Denise Bacher wrote: > I'm still having problems understanding how to do problem 10. I've looked at the > grammar and the helping functions, but I don't know where to start. I'm not sure > how to break it down into smaller pieces, or which pieces to break it down into. > Are there any hints, tips or help you can offer me? Try looking at the example in the library, which is in remove-named-mod.scm (also available from the code examples web page). Basically you extract the element from the document, and pass it to a helper that deals with elements, get the element back and reform the document. The element helper also checks the name of the element; if it matches, then it's marked, otherwise, the children are obtained and each child-of-element in that list of children is also marked, using map (or another helper for lists of child-of-element) and another helper for child-of-element. When you get the list back, form it up into an element again. Do the same for child-of-element. In working with a child-of-element, note that only one case of the 5 alternatives can possibly contain an element. For that case, you call your element helper, and then reform it into a child-of-element. 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 -------------------------