From - Thu Nov 29 12:52:21 2001 Return-Path: Received: from cs.iastate.edu (leavens.cs.iastate.edu [129.186.3.47]) by css-1.cs.iastate.edu (8.9.0/8.9.0) with ESMTP id MAA09450; Thu, 29 Nov 2001 12:49:26 -0600 (CST) Message-ID: <3C068310.69C77E63@cs.iastate.edu> Date: Thu, 29 Nov 2001 12:48:48 -0600 From: "Gary T. Leavens" Organization: Department of Computer Science, Iowa State University X-Mailer: Mozilla 4.78 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Aaron Forsyth Subject: Re: Hw6 Question References: <200111291818.MAA24006@mailhub-2.iastate.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Aaron, Aaron Forsyth wrote: > I was wondering what we should hand in for problem 3. I have a transcript of > all the test cases passing. Should I print the code that is in the my-3-1- > grammar.scm and my-3-1.scm files now, or should I wait till I am finished with > the following problems that build on this one? I would like to know before I > move on and start changing the files for the next problem. I'd wait to print until you are done with all the problems, since the same files will contain all of the solutions. Just put comments (on lines starting with a semicolon (;)) in to show what parts are solving what problems. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1040 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 From leavens@cs.iastate.edu Sat Dec 1 14:48:47 2001 Date: Sat, 1 Dec 2001 14:44:51 -0600 (CST) From: Gary T. Leavens To: Aaron R Forsyth Cc: Computer Science 342 Staff Subject: Re: HW6 Question on the unpack problem. Aaron, On Sat, 1 Dec 2001, Aaron R Forsyth wrote: > I am having trouble with the parser for the unpack problem. I know I want > to take in a list of symbols separated only by spaces. How do I do that? > This is what I have tried to put in the my-3-1-grammar.scm file: None of these are right: > (expression ("unpack" (list expression) "=" expression "in" expression) > unpack-exp) The "list" primitive of Scheme doesn't tell SLLGEN anything. > (expression ("unpack" (separated-list expression "") "=" expression "in" > expression) unpack-exp) You can't separate a list by empty strings. > (expression ("unpack" (separated-list symbol "") "=" expression "in" > expression) unpack-exp) Similarly. > (expression ("unpack" (separated-list symbol " ") "=" expression "in" > expression) unpack-exp) The spaces are ignored by the lexical grammar, so you can't have a list separated by spaces, because space tokens don't get to the context free grammar's parser. > (expression ("unpack" (list symbol) "=" expression "in" expression) unpack-exp) Again, "list" is of no help here. What you want is to use arbno instead of separated-list, since the lexical analyzer ignores spaces. For example, here's the SLLGEN grammar specification for let expressions: (expression ("let" (arbno identifier "=" expression) "in" expression) let-exp) You can use "arbno" anyplace where there's a Kleene star in the grammar for SLLGEN. Does that help? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1040 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 From leavens@cs.iastate.edu Mon Dec 3 09:05:43 2001 Date: Mon, 3 Dec 2001 08:59:46 -0600 (CST) From: Gary T. Leavens To: Mark M. Lanning Cc: Computer Science 342 Staff Subject: Re: HW6 problem 5 Mark, On Sun, 2 Dec 2001, Mark M. Lanning wrote: > Dr. Leavens, > > I am having problems implementing the emptylist. I don't see how > emptylist is a primitive type. It seems like it should be with the > expression types but in the problem statement in the book it says "add > list primitives to the language" > > Based on the grammar a primitive is followed by a "(" such as "+(3,2)" > where "+" is the primitive. Yes, emptylist is not a primitive procedure, so it's not like "+" or "car" in that respect. > Where does the empty list go? Can the empty list in the cases be > defined as '() or as (list ) ? It should be added as a name in the initial environment. You may recall that we added the names "zero" and "one" to the initial environment during our first class discussing interpreters by doing precisely this. See the file "$PUB/lib/3-1-modified-in-class.scm" for how to do that and look at the definition of init-env. Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1040 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 From leavens@cs.iastate.edu Mon Dec 3 09:06:05 2001 Date: Mon, 3 Dec 2001 09:04:13 -0600 (CST) From: Gary T. Leavens To: Mark M. Lanning Cc: Computer Science 342 Staff Subject: Re: One more question Mark, On Mon, 3 Dec 2001, Mark M. Lanning wrote: > Not to ask to many questions but how do you go from a boolen expression > like zero? To a 0 or 1? > > I have the following for equal? And zero? And the number->expressed > doesn't complain but I get #t and #f from that procedure. Is there any > way to get a 0 or a 1 instead of #t and #f? Recall that when we discussed how to do conditionals, we added a procedure, true-value? with the type (-> (expressed-value) boolean)). See the interpreter $PUB/lib/3-4.scm for an example of this with the right type casts. You need to do something similar, using a Scheme if, to write a procedure with type (-> (boolean) expressed-value). Using expressed-value as the return type of this is necessary to make it type check. Does that help? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1040 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 From leavens@cs.iastate.edu Wed Dec 5 00:34:26 2001 Date: Wed, 5 Dec 2001 00:26:38 -0600 (CST) From: Gary T. Leavens To: Nick Veys Cc: Gary T. Leavens Subject: Re: ComS 342 Homework 6 Question. Nick, On Tue, 4 Dec 2001, Nick Veys wrote: > Hi, I'm having some trouble with HW6 Question 5. > > It's as if my "car" and "cdr" don't do anything at all: > > ........ > (car-prim () (car args)) > > (cdr-prim () (list->expressed (cdr args))) > ........ > > that's the apply-primitive snippet, and they are defined in the datatype > as well. Yes, you wrote the code for car-prim so it returns the first argument without doing anything to it. Look at the code for add-prim, for example: (add-prim () (number->expressed (+ (expressed->number (car args)) (expressed->number (cadr args))))) Here (car args) is the first argument, and (cadr args) is the second argument to add-prim. That is, if you write "+(2,3)" in the defined language, then args is the list (2 3), so (car args) is 2, and (cadr args) is 3. So, for implementing car-prim, when you take a case like: > (run "car(list(5, 4, 1, 9, 8, 7))") args is the list ((5 4 1 9 8 7)), i.e., a list whose only element is the list (5 4 1 9 8 7), so (car args) is that list: (4 4 1 9 8 7). You have to take the car of that, i.e., the car of (car args), otherwise you get just (car args) which is: > ==> (5 4 1 9 8 7) instead of > EXPECTED: 5 > (run "cdr(list(5, 4, 1, 9, 8, 7))") > ==> () > EXPECTED: (4 1 9 8 7) This is the same kind of problem, except here you are throwing away the only argument you have in the list args by using cdr first. Does that make sense? Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1040 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580