From leavens@cs.iastate.edu Fri Apr 2 13:46:09 2004 Date: Fri, 2 Apr 2004 13:44:21 -0600 (CST) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: Computer Science 342 Staff Subject: Re: #11, hw6. Hi Cindy, On Fri, 2 Apr 2004 cindyhsu@iastate.edu wrote: > For the let problem, (#11), can we use any "letrec" or "proc" to loop the procedure? > Or are we suppose to do it in a long nested way? Or is there a trick in using > let for loop? You are supposed to use nested lets to do this. You can use a logrithmic number of lets, so it's not too much typing (don't use 64 of them). -- 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@cs.iastate.edu Fri Apr 2 16:27:10 2004 Date: Fri, 2 Apr 2004 16:26:53 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: HW6 Problem 5 Hi Jason, On Fri, 2 Apr 2004, Jason Cook wrote: > > > Error reported by cases: > > > Bad clause: (list-prim () ...) > > > > > > What is that implying? > > > > This means that the define-datatype is missing the declaration of the > > variant list-prim. > > Guess I shouldn't forget to uncomment that when I am testing it. > Probably not all that helpful... No problem. I'm glad that was correct. -- 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@cs.iastate.edu Sun Apr 4 23:09:20 2004 Date: Sun, 4 Apr 2004 23:08:33 -0500 (CDT) From: Gary T. Leavens To: David Gillingham Cc: cs342s@cs.iastate.edu Subject: RE: [hw6] emptylist question Hi David, Brian was right, emptylist is supposed to be in the initial environment; it's a name (variable) not a primitive. I think the way you've done that looks okay. The problem you are having is with your definition of cons. The cons primitive in the defined language takes 2 arguments, you need to extract both of them and pass them to Scheme's cons procedure. Look at the other primitives to see how they are extracting the arguments from the list of arguments args: you aren't doing it right... On Sun, 4 Apr 2004, David Gillingham wrote: > I had never even thought of that.well, that seemed to work, but it's causing > problems with my cons procedure. It seems to be keeping the emptylist at > the end of every cons. > > Here's the initial environment created: > > typed> (init-env) > > (extended-env-record (emptylist) #(()) (extended-env-record (i v x) #(1 5 > 10) (empty-env-record))) : environment > > > Here's a case where the cons breaks down: > > (run "cons(342, emptylist)") > ==> (342 ()) > EXPECTED: (342) > > > Here's the code for cons: > > (cons-prim () (list->expressed (cons (car args) (cdr args)))) > > I've tried a few basic permutations with car and cdr to strip that emptylist > part off, but it ends up breaking other test-cases. Is there something > simple I'm missing, or do I have to catch the emptylist with a if-statement? -- 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@cs.iastate.edu Mon Apr 5 15:58:51 2004 Date: Mon, 5 Apr 2004 15:58:37 -0500 (CDT) From: Gary T. Leavens To: David Gillingham Cc: Computer Science 342 Staff Subject: Re: [hw6] unpack question Hi David, On Mon, 5 Apr 2004, David Gillingham wrote: > Is it necessary for us to print an error or would it be sufficient to just > assume the number of identifiers and the list length are equal? For this problem you should explicitly call Scheme's procedure "error" when the lengths differ. That's part of the problem, although the tests don't test for 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@cs.iastate.edu Mon Apr 5 21:42:39 2004 Date: Mon, 5 Apr 2004 21:42:26 -0500 (CDT) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: HW6 Problem 5 Hi Jacob, On Mon, 5 Apr 2004, Jacob Lynch wrote: > I'm having a really hard time putting in the emptylist into the interpreter. > It seems like it should be easy, but I don't understand it. I don't think > I'm supposed to make it a primitive because there are no parentheses after > it, but if I don't do that, then I don't know how to have it recognized. > Thanks for any tips! Put it in the initial environment, like we did with the name zero in class. -- 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@cs.iastate.edu Tue Apr 6 01:27:09 2004 Date: Tue, 6 Apr 2004 01:26:24 -0500 (CDT) From: Gary T. Leavens To: Jonathan Bentz Cc: Computer Science 342 Staff Subject: Re: cs342 homework question Hi Jonathan, On Mon, 5 Apr 2004, Jonathan Bentz wrote: > I'm having some trouble with problem 12, the "unpack" question. In the > problem description, you say that we should use our list primitives that > we have defined. How do we use them in the cases part of > eval-expression? I understand how to use our primitives when I am in > our interpreter but when I'm just writing the code for the interpreter I > don't know how to call the primitive procedures that I added to the > interpreter. I didn't mean that you should call the defined-language primitives from Scheme code. I agree that doesn't make much sense. What I meant was that you should use defined language primitives in doing testing. Essentially, since unpack works with lists, it's impossible to test it without writing code in the defined language that uses the defined language's list primitives. -- 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@cs.iastate.edu Tue Apr 6 01:34:50 2004 Date: Tue, 6 Apr 2004 01:34:31 -0500 (CDT) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: problem 12 On Tue, 6 Apr 2004, Jacob Lynch wrote: > Well, sorry to bother you so much, but hopefully you can clear this problem > up for me. Here's what I have in my grammar file: > > > > (expression > > ("unpack" (arbno symbol) "=" expression "in" expression) unpack-exp) The trouble is that you should use "identifier" instead of "symbol" above. The nonterminal identifier generates a symbol, but symbol itself isn't understood. > I get an error that says I can't start with an "a" or "x" or whatever the > line I happen to try starts with as the first symbol in ids. I'm not sure > what to do about that. I have it defined as a list of symbol in the > interpreter file. I believe this is caused by the problem above. > Also, I don't have any idea what the paragraph in the > description for this problem is talking about with list primitives and let > primitives. All I did for #5 was get [add if, equal?, zero?, greater?, > less?, and null?] those to work. All I meant was that you will need the list primitives in the defined language in order to do testing on unpack. > My basic idea for this problem is just to > compare the lengths of the two lists, return an error if they are not the > same. Yes. > Otherwise, extend the environment with the evaluated exp and pass > that new environment to another eval-expression using the last body > variable. Well, any hints would be great. Thanks very much! That's not quite right. The evaluated expression has a single expressed value, it's a list of expressed values. You need to convert it's type from an expressed value to a list in order to do the bindings. -- 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@cs.iastate.edu Tue Apr 6 21:12:34 2004 Date: Tue, 6 Apr 2004 21:12:17 -0500 (CDT) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: cs342s@cs.iastate.edu Subject: Re: eopl:error question. Hi Cindy, On Tue, 6 Apr 2004 cindyhsu@iastate.edu wrote: > Could someone tell me why my eopl:error won't work? > > (eopl:error 'apply-procval > "Wrong number of actual arguments, " ;;display ends here > i ;;the rest won't come out > ", to procedure" > proc)) It works but you're not using it right. The simpliest thing to do what you are trying to do is to use just error, instead of eopl:error. See p. 14 in the book for an explanation of how eopl:error works. Or look in $PUB/lib/r5rs.scm. For example, typed> (eopl:error 'apply-procval "Wrong number of actual arguments, ~a to procedure ~s" 3 'foo) Error reported by apply-procval: Wrong number of actual arguments, 3 to procedure foo Process scheme finished -- 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 ---------------------------------