From leavens@cs.iastate.edu Fri Mar 12 04:20:59 2004 Date: Fri, 12 Mar 2004 04:09:49 -0600 (CST) From: Gary T. Leavens To: ehennis@iastate.edu Cc: Computer Science 342 Staff Subject: Re: Running Scheme Hi Evan, You probably need to set the environment variables that tell where to find SLIB in the shell scripts needed to run the interepreter. See the Scheme Library page: http://www.cs.iastate.edu/~cs342/library.shtml where, at the bottom is a list of the scripts. Be sure to edit them. On Thu, 11 Mar 2004 ehennis@iastate.edu wrote: > I just go Fedora Linux installed and I am trying to get scheme running. I > installed chez scheme and and trying to get SLIB working too. I downloaded SLIB > 3a1. I got a lot of errors. The main one is that scm not found along with a few > about not making a make file. > DO you have any idea what is wrong? -- 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 Sat Mar 20 12:47:08 2004 Date: Sat, 20 Mar 2004 12:46:49 -0600 (CST) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: Computer Science 342 Students and Staff -- Amin Babaei-Bourojeni , Brian Wicks , Com_S_342 , Computer Science 342 Staff , Chun Yu , Iris , Bobby Myers , Nick Shafer , Varnit Khanna Subject: Re: inf-set problem (correction to hw5, problem 3) Hi Cindy, On Fri, 19 Mar 2004 cindyhsu@iastate.edu wrote: > I have a question on the inf-set homework. (On homework 5, problem 3) > Here is a bug that I don't know how > to fix: > > typed> (define greater-than-maker > (lambda (n) > (inf-set-comprehend (lambda (m) (> m n))))) > : line 4: Operator and argument types don't match > Offending call: (inf-set-comprehend (lambda (m) (> m n))) > Operator type : (-> ((-> (datum) boolean)) inf-set) > Argument type list: ((-> (number) boolean)) ;;isn't number a kind of > datum?? > Skipping evaluation because of the type errors... Yes, number is a subtype of datum, but that means that (-> (number) boolean) is not a subtype of (-> (datum) boolean), since if we passed a list to the procedure of type (-> (number) boolean), it would fail, but it shouldn't if it has type (-> (datum) boolean). So the example really doesn't type check. That is, the example (not your code) is wrong. It has to be something like ... (define greater-than-maker (lambda (n) (inf-set-comprehend (lambda (x) (and (number? x) (> (has-type-trusted number x) n)))))) I'm sorry for the use of has-type-trusted, there's no good way to force the type checker to get the right type in this case... So for this problem, it's okay if you ignore the type checker during testing, but your code should be able to be type checked. I have fixed the example in the $PUB/homework/hw5.txt file and also the test cases in $PUB/homework/hw5/inf-set.tst that is run when you do (test-hw5 "inf-set") My apologies for the mistake. Thanks for bringing it to my attention. -- 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 pastaman@iastate.edu Mon Mar 22 03:47:04 2004 Date: Sun, 21 Mar 2004 01:09:31 -0600 From: Michael Skinner To: Gary T. Leavens Subject: kuro5hin.org scheme article... Howdy Dr. Levens, I'm sure you don't waste much time surfing the web for 'neat' stuff as I do, so you might have missed this rather interesting article on scheme, and why the author likes it. http://www.kuro5hin.org/story/2004/3/17/93442/8657 Michael Skinner From leavens@cs.iastate.edu Wed Mar 24 11:19:37 2004 Date: Wed, 24 Mar 2004 11:19:23 -0600 (CST) From: Gary T. Leavens To: Brian Dorn Cc: cs342s@cs.iastate.edu Subject: Re: Late policy for HW3, 19 Hi Brian, On Wed, 24 Mar 2004, Brian Dorn wrote: > I've been working on grading HW3, 19 and I have a question about which late > policy to apply. The new policy was posted the same day that this problem > was due, so I would assume we would use the old policy. However on the > course website it says that we will make an exception to the new late policy > for this problem beign turned in following spring break for 40%. Yes, that's right, what is on the web is what I announced in class. > Which > penalites should I apply for things turned in on say the 11th and 12th of > March (2 and 3 days late)? The new policy, so for 2 days late it's the next lecture meeting, so it's 10%. For 3 days late it's before 5 days, so it's 20%. -- 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 Thu Mar 25 04:59:16 2004 Date: Thu, 25 Mar 2004 04:55:31 -0600 (CST) From: Gary T. Leavens To: Chris Campbell Cc: Computer Science 342 Staff Subject: Re: 342 questions, forall Hi Chris, Brian, I agree with Brian's answer (thanks Brian). You can also look at the course resources page, which has a link to the description of our type notation with more examples. See also more directly: http://www.cs.iastate.edu/~cs342/docs/typedscm_toc.html On Wed, 24 Mar 2004 dorn@cs.iastate.edu wrote: > forall is a universal quantifier that indicates the procedure can take any > object of a generic type (which we call T). > > So this means the cell procedure can do the following: > > (cell 4) will give us back a (cell-of number) > (cell 'x) will give back a (cell-of symbol) > > Here the cell procedure can take a value of any type T and it will give you back > a (cell-of "that-same-type-T"). In the above examples, we use numbers and > symbols, but any type can work there. Notice that this means the code can't > really assume much about the input data's type. > > For cell-ref it says that the procedure takes something that has type (cell-of > T) and returns a value of type T. So if we do: > > (cell-ref (cell 5)) --> 5 : number > (cell-ref (cell 'x)) --> x : symbol > > Remember that (cell 5) gives us a (cell-of number), etc. Does this make sense? > > Brian > > > Quoting Chris Campbell : > > > I am confused about what the forall (T) is doing, for example the > > following deftype. Could you please explain this to me? thanks. > > Anything I should look over on the course web page, etc.?? > > > > > > (deftype cell > > (forall (T) (-> (T) (cell-of T)))) > > (deftype cell-ref > > (forall (T) (-> ((cell-of T)) T))) > > > > > > > > > > -Chris > > > > > -- 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 Thu Mar 25 04:59:37 2004 Date: Thu, 25 Mar 2004 04:58:53 -0600 (CST) From: Gary T. Leavens To: ireneon@cs.iastate.edu Cc: cs342s@cs.iastate.edu Subject: Re: questions on exam2 #6 Hi Wing-on, On Thu, 25 Mar 2004 ireneon@cs.iastate.edu wrote: > > Dear Prof. Leavens, I have a question about #6 on exam 2. Here is my code for > the problem. On line 7 and 9, I've been taken 1 point off for repeated code. > Could you tell me how to avoid the repeated code here? I thought about writing > a helping procedure, but I think it doesn't worth to write another procedure to > replace just one extra line of code. Is there any other methods to avoid the > repeated code here? Please show me how, thank you very much. > > 1 (deftype has-times? (-> ((list-of sym-exp)) boolean)) > 2 (define has-times? > 3 (lambda (slst) > 4 (and (not (null? slst)) > 5 (if (sym-exp-slist? (car slst)) > 6 (or (has-times? (sym-exp->slist (car slst))) > 7 (has-times? (cdr slst))) > 8 (or (equal? '* (sym-exp->symbol (car slst))) > 9 (has-times? (cdr slst))))))) The probelm is that you aren't handling the lists all in one procedure. If you had used two procedures you would have avoided this problem, as in the following: (deftype has-times? (-> ((list-of sym-exp)) boolean)) (define has-times? (lambda (slst) (and (not (null? slst)) (or (has-times-se? (car slst)) (has-times? (cdr slst)))))) (deftype has-times-se? (-> (sym-exp) boolean)) (define has-times-se? (lambda (se) (if (sym-exp-symbol? se) (eq? '* (sym-exp->symbol se)) (has-times? (sym-exp->s-list se))))) The idea in this is that each procedure only deals with one kind of type, this avoids the duplication of cases in your code because each part of the data only comes up in one place. -- 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 Mar 28 06:35:09 2004 Date: Sun, 28 Mar 2004 06:34:24 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: cs342s@cs.iastate.edu Subject: Re: More Strength Reduce Problems Hi Jason, The probelm with your code is that you are using tests like the following, which are wrong: > (cond > ((equal? op exponent-op) ;; ...) > ((equal? op times-op) ;; ... > (else > a-expr))) > > This would type check fine but always return a-expr because for > some reason it would never think (equal? op exponent-op) or (equal? > op times-op) was true. (I realize that unary-minus-exp is not > correct yet). The reason is twofold. First exponent-op and times-op are procedures, not symbols, so they will never be equal to the data structures used to represent the type infix-op (i.e., the argument op). Second, you shouldn't be testing objects of the type infix-op using equal?, instead you should write a test using the "cases" special form, because infix-op is defined by a grammar. The following has the same problem: > (cond > ((equal? (unparse-infix-op op) '**) ;; ... ) > ((equal? (unparse-infix-op op) '*) ;; ... ) > (else ;; ...)) > > After I changed it to that it wouldn't let me use a-expr for any of > the else types because it gave some type error. So I changed those > to return (binary-op-exp left-arg op right-arg) or in other words > to return the same arith-expr since it wouldn't need reducing. > Well now that doesn't type check and I don't understand why. Also > am I doing the tests to see if the operators are equal correctly? > (equal? (unparse-infix-op op) '*) etc.? No. That is the main problem. > I made the helper function > because I needed to test if the lit-exp value was a 2 for the > various cases. Am I making it too complicated? Yes, that helper seems wrong to me. > I realize that > this function is also not completely correct because it > doesn't/can't check the left arg of any binary-op-exp, but I also > can't figure out how to call that same function with both of those > arguments. Call each separately if you want to do that. But the problem only requires looking at the right argument of an exponent. > Do I at least have the conditions correct for what to return if > there is an exponent or times? If not, what am I doing wrong and > how can it be different? You may have to do two passes over the expression to get 2 ** 2 reduced to 2 * 2 and then 2 + 2. > Here is the type error I get now: > > strength-reduce.scm: line 18: Operator and argument types don't > match > Offending call: (binary-op-exp left-arg op right-arg) > Operator type : (forall (t) (-> (t (-> () infix-op) t) arith- > expr)) > Argument type list: ((forall (t) t) infix-op (forall (t) t)) > strength-reduce.scm: line 24: Operator and argument types don't > match > Offending call: (binary-op-exp left-arg op right-arg) > Operator type : (forall (t) (-> (t (-> () infix-op) t) arith- > expr)) > Argument type list: ((forall (t) t) infix-op (forall (t) t)) > strength-reduce.scm: line 26: Operator and argument types don't > match > Offending call: (binary-op-exp left-arg op right-arg) > Operator type : (forall (t) (-> (t (-> () infix-op) t) arith- > expr)) > Argument type list: ((forall (t) t) infix-op (forall (t) t)) I wouldn't worry about this type error, as it's the result of errors introduced elsewhere due to the other mistakes you made. -- 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 Mar 28 21:23:27 2004 Date: Sun, 28 Mar 2004 21:23:10 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: strength-reduce Hi Jason, On Sun, 28 Mar 2004, Jason Cook wrote: > Why does this not work for replacing one operator with another? (I > realize that it isn't a correct solution, but shouldn't it at least > replace one op with another correctly?) (No it shouldn't...) > (deftype strength-reduce (-> (arith-expr) arith-expr)) > (define strength-reduce > (lambda (a-expr) > (cases arith-expr a-expr > (lit-exp (datum) (lit-exp datum)) > (binary-op-exp (left-arg op right-arg) > (binary-op-exp left-arg (operators op) right-arg)) > (unary-minus-exp (arg) (unary-minus-exp (strength-reduce > arg)))))) > > (deftype operators (-> (infix-op) infix-op)) > (define operators > (lambda (oper) > (cases infix-op oper > (exponent-op () times-op) > (times-op () plus-op) > (minus-op () minus-op) > (plus-op () plus-op)))) The problem is in the definition of operators, whcih doesn't have the right type. The variables times-op and plus-op do not denote symbols, they denote procedures. typed> (load-from-lib "arith-expr.scm") Type checking "arith-expr.scm" ... ... done type checking "arith-expr.scm" ... infix-op? : (type-predicate-for infix-op) infix-op : (variant-record (plus-op) (minus-op) (times-op) (exponent-op)) plus-op : (-> () infix-op) minus-op : (-> () infix-op) times-op : (-> () infix-op) exponent-op : (-> () infix-op) loading /home/course/cs342/public/lib/arith-expr.scm ... typed> plus-op # : (-> () infix-op) typed> > I also do not understand how to check if the right-arg is a 2. I > assume I need a helper, but what would it take and return, and what > would the other cases do? If it returns a boolean, then the other cases can return false (#f). It could just take the right-arg itself, and see if it's (lit-exp 2). > Can you give me some examples of two cases working together that > return the same type but a different instance? I really have no > idea how to proceed whatsoever and everything I try doesn't type > check, short of making it return the exact same thing. I put some examples (just now) in $PUB/lib/airth-expr-examples.scm. Do these help? -- 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 ---------------------------------- A student asked me about the following error output in homework 5's inf-set-as-ast problem: (inf-set-member? 5 less-than-6-or-greater-than-48) Error: attempt to apply non-procedure (intersected (comprehended #) (comprehended #)). This resulted from the use of the AST representation as a procedure instead of using inf-set-member? in the code for negation. That works in the procedural representation, but not in the AST representation. -----------------------------------