From leavens@larch.cs.iastate.edu Mon Dec 4 17:17:10 2006 Date: Mon, 4 Dec 2006 17:17:10 -0600 (CST) From: Gary T. Leavens To: Adam M Weber Cc: Steve Shaner Subject: Re: hw10 problems 4 and 7 Hi Adam, On Mon, 4 Dec 2006, Adam M Weber wrote: > I am having trouble with number 4 on the conz, caz, and cdz part. > > I guess is there any hints you can give for these. The most important hint is that in this problem I had to change the way primapp-exp works in general, because conz needs to get targets, not expressed values. If eval-expression's primapp-exp case already evaluates all the arguments to expressed values, then it's too late for conz to not evaluate the arguments. No other primitive needs this behavior, so if the primitive is not conz, then you can proceed to evaluate the arguments and call the existing code apply-primitive code, with added cases for caz and cdz and random. You could, for example, rename the existing apply-primitive as apply-strict-primitive, and then call that from a new apply-primitive that takes a list of targets as arguments. Other ways may also work. > I also was wondering if there were any test cases you specifically wanted > for number 7. Just test assert with some expressions that evaluate to 0 and some that evaluate to a non-zero value (false and true). Since there really isn't much else to do, 3 or 4 test cases is probably enough. 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 Dec 11 10:22:38 2006 Date: Mon, 11 Dec 2006 10:22:38 -0600 (CST) From: Gary T. Leavens To: Adam M Weber Cc: Steve Shaner Subject: Re: practice exam Hi Adam, On Mon, 11 Dec 2006, Adam M Weber wrote: > Would it be possible for you to tell me what the answer to number 2 on the > Spring 2006 practice exam is? > > I have the following as an answer > > (freeze-exp (body) > (procval->expressed (closure '() '(body) env))) > > and that is it so far. That's close, but you should use "body" instead of "'(body)", as the second argument to closure is an expression, not a list of symbols. So it's (deftype eval-expression (-> (expression environment) Expressed-Value)) (define eval-expression (lambda (exp env) (cases expression exp ;; ... assume the other expression cases are done, ;; and add code for freeze and thaw below... (freeze-exp (body) (procval->expressed (closure '() body env))) (thaw-exp (body) (let ((proc (eval-expression body env))) (apply-procval (expressed->procval proc) '()))) ))) That is, thaw just applys the closure that is returned by evaluating the body of the thaw expression. 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 ------------------------------------