From leavens@cs.iastate.edu Sun Nov 4 15:33:57 2001 Date: Sun, 4 Nov 2001 15:30:53 -0600 (CST) From: Gary T. Leavens To: Aaron R Forsyth Cc: cs342s@cs.iastate.edu Subject: Re: HW4, problem 3 Aaron, On Sun, 4 Nov 2001, Aaron R Forsyth wrote: > I am having a problem with the strength-reduce problem. > > I am not understanding when evaluate the expression or when to leave it in > arith-expr form. I have tried evaluating the expression (using the > eval-arith-expr in problem 2) if the expression is not an expression that > will strength-reduce. I have also tried only evaluating the expression if > it will evaluate to be 2, otherwise leave it as it is. Both of these have > caused the test cases to hang on certain tests. > > Could you help clear up how to know which expressions to evaluate and which > ones to leave in arith-expr form? Thanks. In this problem you are not to evaluate expressions or subexpressions at all. You are to leave them all in arith-expr form. You will need to test when one has a certain shape, containing a 2 in the right place. However, you shouldn't use eval-arith-expr in this problem at all. 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 Nov 5 22:18:43 2001 Date: Mon, 05 Nov 2001 22:10:39 -0600 From: Gary T. Leavens To: Randall P Mersch Subject: Re: hw4 Randy, Randall P Mersch wrote: > Professor, I saw that the first problem doesn't have to be type > checked. Is that just the first one, or all the rest of the problems > too? It doesn't say one way or the other after that, just want to make > sure, thanks~ The rest are supposed to type check. -- 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 Tue Nov 6 08:58:15 2001 Date: Tue, 6 Nov 2001 08:57:41 -0600 (CST) From: Gary T. Leavens To: Yuriy I. Gettya Cc: cs342s@cs.iastate.edu Subject: Re: strength-reduce Yuriy, On Tue, 6 Nov 2001, Yuriy I. Gettya wrote: > I've got a question regarding using cases in the subj.: > In the code like this: > > ... > (cases arith-expr ae > (binary-op-exp (l op r) > > ... > > I can't figure out how to check for the type and value of r by using cases > again without the expression forgetting that there's also the left part - l. > In other words, if i use (cases arith-expr r) again in the place of > the outer cases forge[t]s the value of the l and op ... The values of l and op etc aren't forgotten if you use a nested case. But you have to choose differnent names for these formals in a nested expression if you want to do that. Alternatives are to define helping procedures which do their own cases and to use a let expression to do renaming. > Also is it by design that there's no way to chek for lit-exp? for example? > using cases all the time is way over the head tedious.. You can define your own helping procedure lit-exp? using cases if you wish. It's just not provided automatically. 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 Nov 7 14:55:45 2001 Date: Wed, 07 Nov 2001 14:42:35 -0600 From: Gary T. Leavens To: dongshin kim Cc: Gary Leavens , George Ushakov , Facundo Bromberg , Com_S_342 , Wen-Chieh Chang , Chunrong Pan , Dong-Shin Kim Subject: Re: Bug in homework5, problems 3 and 4 Hi, Dong-Shin Kim wrote: > In the middle of qustion number 3. > > "Start by copying the file > $PUB/homework/inf-set-as-proc.scm to your directory." > > Actually, it should be > $PUB/homework/hw5/inf-set-as-proc.scm That's correct. Thanks for pointing this out. I've made the correction in the homework file. Note that problem 4 had the same problem, which has also been corrected. -- 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 Nov 7 22:34:28 2001 Date: Wed, 7 Nov 2001 22:33:50 -0600 (CST) From: Gary T. Leavens To: Benjamin T Rittgers Cc: cs342s@cs.iastate.edu Subject: Re: homework 5, problem 3 Benjamin, On Wed, 7 Nov 2001, Benjamin T Rittgers wrote: > What [does] the output of inf-set-comprehend look like[?] It is very hard to > code it if the output is not known. I know it takes a boolean function as > an input and outputs an inf-set. I just do not understand what it is > supposed to do because all the test cases only use that function as an > argument, so I cannot trick the script to say: EXPECTED inf-set in > blah-blah-blah format. > > There need to be a test case that only tests inf-set-comprehend. Or at > least have some sample output for that on the assignment. It is impossible > to follow what is going on. I don't see why. We discussed this in sections today, or rather a very similar example. Also the seq example is quite similar. And the problem itself says that the representation is a procedure (look at the defrep, for example). Since the representation is a procedure, the output of inf-set-comprehend is, of course, a procedure, which is what represents the inf-set. All of that is much more informative than the answer to your question, which is, for example: typed> (inf-set-comprehend (lambda (x) #t)) # : inf-set So it's a procedure. Of course, that's the same thing you get if you do: typed> (lambda (x) #t) # : (forall (t) (-> (t) boolean)) except that the type is different. I think you're trying to make this problem too hard. The inf-set-comprehend procedure is *very* simple. What's the simplest procedure you can imagine that has the right type for it? Try that... 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 Thu Nov 8 00:04:42 2001 Date: Thu, 8 Nov 2001 00:02:30 -0600 (CST) From: Gary T. Leavens To: Yuriy I. Gettya Cc: cs342s@cs.iastate.edu Subject: Re: homework 5, problem 3, inf-set-complement Yuriy, On Wed, 7 Nov 2001, Yuriy I. Gettya wrote: > Could you elaborate on the innner workings of the subj? > I'm in doubt as to how it should behave... (I'm not exactly sure what you mean by "subj", do you mean "subject"? So I guess the question is how inf-set-complement should behave....) For one thing, (inf-set-complement (inf-set-comprehend (lambda (x) #t))) should behave the same as (inf-set-comprehend (lambda (x) #f))). Similarly, (inf-set-complement (inf-set-comprehend (lambda (x) #f))) should behave the same as (inf-set-comprehend (lambda (x) #t))). Another way to specify this is to say that, for all datum x, and for all inf-sets s, (inf-set-member? x (inf-set-complement s)) = (not (inf-set-member? x s)) For example, (inf-set-member? 7 (inf-set-comprehend (lambda (x) (equal? 7 x))))) ==> #t so (inf-set-member? 7 (inf-set-complement (inf-set-comprehend (lambda (x) (equal? 7 x))))) ==> #f Similarly, note that for all datum x, and all inf-sets s1 and s2, (inf-set-member? x (inf-set-union s1 s2)) = (or (inf-set-member? x s1) (inf-set-member? x s2)) (inf-set-member? x (inf-set-intersection s1 s2)) = (and (inf-set-member? x s1) (inf-set-member? x s2)) 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 Thu Nov 8 01:04:13 2001 Date: Thu, 8 Nov 2001 01:02:55 -0600 (CST) From: Gary T. Leavens To: Yuriy I. Gettya Cc: cs342s@cs.iastate.edu Subject: RE: homework 5, problem 3, inf-set-union and intersection Yuriy, Thanks for the explanation of FIDO. Interesting. On Thu, 8 Nov 2001, Yuriy I. Gettya wrote: > I'm still struggling with set-union and set-intersection - they have > to return the inf-set again and I just don't see how's that possible... =\ In the procedural representation, an inf-set is represented by a procedure. So these must return a procedure. In Scheme, lambda makes procedures. Look at the examples in the code examples web page for some more examples of this. 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 Fri Nov 9 21:23:23 2001 Date: Fri, 09 Nov 2001 21:05:37 -0600 From: Gary T. Leavens To: Ronald Sidharta Subject: Re: Emacs question Ronald, Ronald Sidharta wrote: > Hi Dr. Leavens, > > I have emacs question for you, > In class, you used the emacs editor that apparently looked like it is > connected to a remote host, is it connected to remote host ? or is it a > stand alone application ? or is it a telnet program ? No, it's not connected to any remote host. It's just a stand-alone windows application. > Where did you download that ? http://www.gnu.org/software/emacs/windows/ See also my web page http://www.cs.iastate.edu/~leavens/. In the helpful resources section are all the customization files I use on my PC to run emacs, the Unix style shell, etc. > one more question: > I know how to divide the screen into 2, but I don't know how to make the > other screen running the scheme interpreter.... You use the command M-x run-scheme, which can be typed as ESC x run-scheme. To learn more about emacs, a good way is to browse the on-line manual, which is available from the help menu item or press function key f1 and then i, then m then emacs, then hit return. 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 Sat Nov 10 11:21:30 2001 Date: Sat, 10 Nov 2001 11:20:51 -0600 (CST) From: Gary T. Leavens To: Ronald Sidharta Cc: cs342s@cs.iastate.edu Subject: Re: Emacs question Ronald, On Sat, 10 Nov 2001, Ronald Sidharta wrote: > Dr. Leavnes, thank you for replying to my mail, > Now, I have emacs for windows, even though it doesn't run scheme > interpreter, I read your website about setting it up, but I don't > understand. Yes, there aren't really directions there, just files :-). > If it is not too complicated, and you have little time > my question is: > how do you make emacs for Windows run the scheme interpreter ? The trick is to have emacs set up as in my customization files so that it calls out the the appropriate shell script (or bat files). I put the shell scripts I use in my "bin" directory and the bat files in my "bat" directory which hang off the web page you saw. > how do you set up cygwin so it will run emacs ? Just install it and then make a shell script like the emacs script in my bin directory. > a quick question: > I can now run scheme interpreter in emacs when I telneted to comp sci > machine, > but it is not scheme342typed interpreter > how can I run scheme342typed with emacs ? You can do this in two ways. First run the scheme interpreter, and then type (load "type-check-and-eval.scm") to it. That loads up the type checker. Or, to do that automatically, before typing M-x run-scheme RETURN, type M-x typed RETURN, and then do M-x run-scheme RETURN. You can use M-x untyped RETURN to switch back to the untyped interpreter within an emacs session. 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 Nov 14 22:23:31 2001 Date: Wed, 14 Nov 2001 22:04:25 -0600 (CST) From: Gary T. Leavens To: Georgiy A Ushakov Cc: RahimAsif@hotmail.com Subject: Re: Fwd: Question on Exam 3 George, Muhammad, On Wed, 14 Nov 2001, Georgiy A Ushakov wrote: > >I have some problems with desugaring . Specifically, I am stuck at this > >problem from previous year's exam. > > > >(let ((v (and q r) > > (w (or s t))) > >(f v w)) > > > >the question is to rewrite the expression without using let, and & or. I > >know how to desugar a let expression but I am not exactly sure about how > >to desugar the and & or. It would be great if you could send me the > >solution to this problem. The rules I described in class (see the lectures/syntax-abstraction/logical-connectives.txt directory from the web page) are as follows: (or ) = #f (or e1 e2 ...) = (if e1 #t (or e2 ...)) (and ) = #t (and e1 e2 ...) = (if e1 (and e2 ...) #f) Actually, in Scheme anything not #f is true, so the real rule for "or" is a bit more complex in reality, see the Revised^5 Report on Scheme for the truth. So the answer to this problem is: (let ((v (and q r) (w (or s t))) (f v w)) = {by the desugaring rule for let} ((lambda (v w) (f v w)) (and q r) (or s t)) = {by the desugaring rule for and} ((lambda (v w) (f v w)) (if q (if r #t #f) #f) (or s t)) = {by the desugaring rule for or} ((lambda (v w) (f v w)) (if q (if r #t #f) #f) (if s #t (if t #f) #f)) > >Also, what exactly is the desugared form of case? I was guessing it is > >cond but apparently cond itself is a sugared form. Please shed some light > >on the matter! Thanks For case it's the left side below desugars to the right side below. (let ((*key* e)) (case e (cond (kl1 b1) ((memv *key* 'kl1) b1) (kl2 b2) ((memv *key* 'kl2) b2) ... ==> ... (kln bn) ((memv *key* 'kl3) b3) (else be)) (else be))) You're right, then you apply the desugaring for cond. (cond (test1 body1) (if test1 body1 (test2 body2) (if test2 body2 ... ... (testn bodyn) (if testn bodyn (else bodye)) bodye) ... )) 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