From leavens@larch.cs.iastate.edu Tue Mar 7 20:42:49 2006 Date: Tue, 7 Mar 2006 20:42:49 -0600 (CST) From: Gary T. Leavens To: Chris Cornelison Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS342 - Interpreter Hi Chris, On Tue, 7 Mar 2006, Chris Cornelison wrote: > Gary, > > I noticed that apply-primitive in the text pg 74, seems to assume that there > either one or two arguments. Something like > > +(3,4) or add1(2) yes. > However, it looks like the grammar allows for more than 2 arguments such > as... > > +(3,4,2) > > ::= ({}*(,)) Right. > I'm I miss-reading one of these? Does our simple interpreter support > expressions such as... > > +(3,4,2) The grammar permits it, but the interpreter in ch3-1.scm only looks at 2 arguments for +. See the apply-primitive procedure. Problem 3 on homework 8 is something like checking that the argument number is right. I'm willing to give some extra credit if you would like to code up that. 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 Sat Mar 18 00:40:31 2006 Date: Sat, 18 Mar 2006 00:40:31 -0600 (CST) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Problem with Homework #7, lib files? Hi Rich, On Fri, 17 Mar 2006 rmatus@cs.iastate.edu wrote: > I'm trying to install all the stuff for homework #7, and I get this error... > > The teachpack file C:\Program Files\PLT\teachpack\drscheme-342-teachpack.scm did > not load properly. > compile: variable not provided (directly or indirectly and at the expected > position) from module: |,c:\program > files\plt\collects\typedscm\tc-scheme-parser| > > I downloaded both the hw7.zip and the lib342.zip files that are on the main > page. Then I opened the lib342.zip file, and moved the two directories into my > PLT directory. Then I did the same with the hw7.zip file as I always do. > > When I tried to run DrScheme, I got that error. > > Did I do something wrong with the install of lib342.zip? Not wrong exactly, but you need to run the "Setup PLT.exe" file that is in the PLT directory (for you, it's in C:\Program Files\PLT). This should fix the problem. It is best to do this each time you reinstall lib342.zip. 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 Mar 20 03:01:05 2006 Date: Mon, 20 Mar 2006 03:01:05 -0600 (CST) From: Gary T. Leavens To: Denise Bacher Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: cs 342 hw7 Hi Denise, On Sun, 19 Mar 2006, Denise Bacher wrote: > I'm working on hw7, and problem 5 has me completly stumped. I've tried a few > things, but none of them have worked, and it errors out before I get a chance to > try to debug it and see where the problem is. Do you have any advice or hints > for me? Thanks > Denise The type checker reports the following (after a while), referring to the second line of cdr-prim in apply-primitive. d:\temp\testing\my-3-1.scm: line 267: Operator and argument types don't match Offending call: (expressed->list (cdr args)) Operator type : (-> (expressed-value) (list-of expressed-value)) Argument type list: ((list-of expressed-value)) You will need to extract an expressed value from args, not a list of expressed values. You also made emptylist a primitive instead of putting it in the environment. A primitive must always be followed by some number of parentheses. So you get the following error. > (run "emptylist") . . my-3-1.scm::2922: parsing: at line 1: looking for "(", found end-marker #f in production ((non-term primitive) (string "(") (arbno seplist16 1) (string ")") (reduce #)) You need to treat emptylist in the initial environment instead of as a primitive. 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 Mar 21 08:38:23 2006 Date: Tue, 21 Mar 2006 08:38:23 -0600 (CST) From: Gary T. Leavens To: Stephen Morgan Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: hw7 question 5 Hi Stephen, On Mon, 20 Mar 2006, Stephen Morgan wrote: > I am having problems with question 5 in hw 7. Below is my code. [... omitted] > car, cdr, and list work but I am having problems with cons and emptylist. Emptylist can't be a primitive, as it doesn't have arguments. It has to be in the initial environment; modify init-env instead of putting it in apply-primitive. 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 Mar 21 08:41:53 2006 Date: Tue, 21 Mar 2006 08:41:53 -0600 (CST) From: Gary T. Leavens To: Stephen Morgan Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: hw7 question 5 Hi Stephen, On Mon, 20 Mar 2006, Stephen Morgan wrote: > I am having problems with question 5 in hw 7. Below is my code. [ omitted ] > Can you give me any hints? I know that just passing the list () deosn't work. Forgot to answer some of this... The problem with cons is that you are using expressed->number on the second argument, but you should be using expressed->list, as the second argument to cons should be a list, not a number. Car should also use expressed->list on its argument, as Scheme's car applies to a list, not to a number. 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 Mar 21 08:46:58 2006 Date: Tue, 21 Mar 2006 08:46:58 -0600 (CST) From: Gary T. Leavens To: David Bireta Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework 7 question Hi David, On Mon, 20 Mar 2006, David Bireta wrote: > I am having trouble getting the cons primitive added as stated in problem 5. > I have this: > > (cons-prim () > (cons (expressed->number (car args)) > args)) Cons takes 2 arguments, which as in add-prim, you have to access using (car args) and (cadr args). This is the first mistake. The first argument to cons is an expressed value, it doesn't have to be a number, so you shouldn't try to use expressed->number on it. The second argument to cons must be a (Scheme) list, so you need to convert it from an Expressed-Value to a list, using expressed->list. > When i type (run "cons(4, emptylist)") it says it is not an expressed > value. so then i try to wrap a list->expressed around it: > > (cons-prim () (list->expressed > (cons (expressed->number (car args)) > args))) > > and it tells me that i have a bad 1st argument. Any ideas or suggestions? I > have a feeling i'm just not converting an expressed value at the right time. It is right to convert back from a Scheme list to an expressed value. The problems are in the rest of it. 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 Mar 21 12:14:14 2006 Date: Tue, 21 Mar 2006 12:14:14 -0600 (CST) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #7, Problem #5... Hi Rich, On Tue, 21 Mar 2006 rmatus@cs.iastate.edu wrote: > Not quite sure I udnerstand why. > > You're given the prim and args... args is all of the things you put into > ()'s... Yes. > so with list (4,5,6) your prim is list and args is a list of (4,5,6) so by > taking car of (4,5,6) shoudln't you get 4? and likewise with cdr? No, if you do car(list(4,5)) then the primitive is car-prim and the list args in the call to apply-primitive for this, overall should be equivalent to: (list (list->expressed (list (number->expressed 4) (number->expressed 5)))) Note that > (define-datatype Expressed-Value expval? (number->expressed (num number?)) (list->expressed (lst (list-of expval?)))) > (list (list->expressed (list (number->expressed 4) (number->expressed 5)))) (list (list->expressed (list (number->expressed 4) (number->expressed 5)))) > (car (list list->expressed (list (number->expressed 4) (number->expressed 5))))) (list->expressed (list (number->expressed 4) (number->expressed 5))) which is not what you want, which is (number->expressed 4). 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 Mar 21 12:53:29 2006 Date: Tue, 21 Mar 2006 12:53:29 -0600 (CST) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #7, Problem #5 cont'd... Hi Rich, On Tue, 21 Mar 2006 rmatus@cs.iastate.edu wrote: >> You shouldn't try to do "car(3)" for example, which is what the if in >> your car-prim is protecting against. That's just a test case that >> doesn't make sense and should give an error if tried. So again, you >> shouldn't need an if. If you want to use an if, test to see if what >> you have is a list before trying to take it's car or cdr, and issue an >> appropriate error message. > But (run "car (3,4,5)") should give me 3, shoudln't it? Ideally that should be an error, because car takes only 1 argument. So this is a bad test case. > and (run "cdr (3,4,5)") should give me (4 5), shoudln't it? Similarly, that should be an error, because cdr takes only 1 argument. So this is a bad test case. > But if I don't have the if statement, everything else crashes because then... > > (car (list (3,4,5)) won't have a number as the first element... Right. Of course car, like in Scheme, should take just 1 argument, which is a list, not a number. 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 -----------------------------------