From leavens@larch.cs.iastate.edu Sun Sep 24 22:02:16 2006 Date: Sun, 24 Sep 2006 22:02:16 -0500 (CDT) From: Gary T. Leavens To: Michael Roberts Cc: Steve Shaner Subject: Re: Com S 342: Hw 4 question Hi Mike, On Sun, 24 Sep 2006, Michael Roberts wrote: > I'm having difficulties with problems over the bexp grammar on the homework. > I can' t get the procedures P? and Q? to work. In the attached code I tried > to use them to test the which variable I'm dealing with, but they always give > the error "reference to undefined identifier: p?". At the moment I'm just > testing for symbol equality, but that doesn't seem "gramatically correct." > Any suggestions? Yes, apparently in DrScheme, you have to use an uppercase "P?", not "p?", to reference a procedure in a module like this. If you use "P?" and "Q?" it will work. There is a "case sensitive" switch in the language menu which is on by default (contrary to R5RS), but it doesn't seem to work to just switch it off. So it seems the only way to work around this is to use upper case for these names. > Also, is it necesary to have a seperate procedure for the production > even though it's very simple? Yes, that's part of following this grammar. 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 Sep 25 18:04:07 2006 Date: Mon, 25 Sep 2006 18:04:07 -0500 (CDT) From: Gary T. Leavens To: Cha0s Subject: Re: Typo in hw 4 Hi Kirk, On Mon, 25 Sep 2006, Cha0s wrote: > There seems to be a typo in the hw4. In the following text, the 3rd > paragraph starting with "You can assume". I'm assuming 'window > layout' should be 'bexp'. I bolded it below. Thanks for catching this cut and past error. > 3. (20 points) [beval] > This is a problem about the boolean expressions discussed in section 5.3 > of the "Following the Grammar" handout. Write a procedure > > beval : (-> (bexp boolean boolean) boolean) > > such that (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. > You are to write this without using Scheme's eval function. > > You can assume that the input window layout has been constructed > according to the grammar. That is, you don't have to check for > errors in the input, and can assume that the input has been parsed. > > -Kirk Sykora > 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 Sep 25 19:27:06 2006 Date: Mon, 25 Sep 2006 19:27:06 -0500 (CDT) From: Gary T. Leavens To: Cha0s Cc: Steve Shaner Subject: Re: HW 4 - Problem 4 Hi Kirk, On Mon, 25 Sep 2006, Cha0s wrote: > In the problem, bswap, it states: > > "Be sure to use a helping procedure, such as bswap-varref, in your solution > so that your code follows the grammar." Yes. > Would it not be following the grammar if we followed the following steps: > > 1. Test if it's a var-exp with (var-exp? be) (if true go to step 2) > 2. Test which varref it is with (P? (var-exp->varref be)) or similar for Q > 3. Build the varref with P or Q as appropriate > 4. Build the varref from step 4 into a bexp with var-exp > 5. Return the bexp built in step 5 > > I built those into my main procedure bswap, and don't really see the need to > branch it out into a bswap-varref, and I think it still follows the > grammar. (But of course, I could be wrong). Good question, but it doesn't follow the grammar if you do all of that in one procedure. Since the grammar has 2 nonterminals, you need to use 2 procedures to follow the grammar according to the definition (see the "Follow the Grammar" handout). Of course, you may think this is overkill in this problem, and you might be right about that. However, you will have to repeat code in step 2 if you do that. Repeated code is a maintenance problem. You will see more advantages to following the grammar in terms of having separate helpers when you get to the statement-expression grammar problems. 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 Sep 26 19:26:56 2006 Date: Tue, 26 Sep 2006 19:26:56 -0500 (CDT) From: Gary T. Leavens To: Eric Brooks Cc: Steve Shaner Subject: Re: CS 342 Homework Hi Eric, On Tue, 26 Sep 2006, Eric Brooks wrote: > A quick question on CS 342 homework #4, problem 14. In the problem you say > > "After doing your own testing you must test your code as for problem 7 above. > After starting a transcript as above, run the tests by typing to Scheme: > > (test-hw4 "vector-index") > > Print the transcript and hand that in with your printout > of the code." > > What do you mean by "starting a transcript as above"? What is supposed to be > handed in with our code? The only other time you've mentioned handing in a > transcript of anything else is when we fail the tests. Sorry, that's a mistaken holdover from an earlier version. I'll fix it. You don't have to do a transcript. 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 Sep 27 22:31:25 2006 Date: Wed, 27 Sep 2006 22:31:24 -0500 (CDT) From: Gary T. Leavens To: Adam M Weber Cc: Steve Shaner Subject: Re: HW4 #10 Hi Mark, On Wed, 27 Sep 2006, Adam M Weber wrote: > Are we supposed to assume for this problem that there are no alternatives in > the grammar for element and attributes. So does that mean we just > recursively call straight through these helper functions without checking > for named? Or attributed? For example. I guess I am just looking for a > little clarification on the following paragraph: > > The type predicates element? and attribute? should not be used in > most programs, as they are slow. But they wouldn't be needed if > you are imagining you are using grammar for and > without alternatives. Sorry for any confusion on this. What I'm saying is that you can pick one of the following 2 grammars to use for and . Either the grammar: ::= ( {}* ) "named (name children)" | ( ( @ {}* ) "attributed (name attributes {}* ) children)" ::= ( ) "name-value (name value)" | ( ) "name-only (name)" or the grammar: ::= ( ( @ {}* ) "element (name attributes {}* ) children)" ::= ( ) "attribute (name value)" In addition I'm saying that if you need to decide if something is an element in the second grammar, you could in theory use the element? procedure, but in fact you shouldn't need to do that in that grammar, as you would just assume that element has the grammar given. A similar comment applies to . Another way of putting this is: if you decide to use the second grammar (which I find more convenient often), then you don't need to use element? but can just use the functions element->name, element->attributes, and element->children. If that's what you mean by "So does that mean we just recursively call straight through these helper functions without checking for named? Or attributed?" then 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