From leavens@cs.uiowa.edu Sun Nov 12 20:09:35 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 20:12:25 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng CC: Yan Liu , Gary Leavens , Mark Allen , Michael Barnes , Mike Bealer , Zhen-Fang Feng , Shawn Garner , Brian Hegland , Kathy Huang , Anthony La Forge , Yi Liu , Xiaoding Luo , John McEchron , Elizabeth Meier , Heath Meyer , Brad Miller , Joseph Morehead , Beena Padanilam , Dong-Jun Park , Kailex Patel , Sonny Pham , ThuyTien Pham , Ben Rogers , Paul Scott , Matt Shera , Suwat Sukchokchai , Xiaolin Sun , Li Tang , Ashley Wong , Jin Zhou , Van Nguyen Subject: Re: 22C54 homework 5, problem 13, no def file Content-Type: text/plain; charset=us-ascii Zhen-fang Feng, Zhen-fang Feng wrote: > Hi, Gary, > > The following description is from problem No.13 in homework 5: > > Put your code in the file infinite-set-ADT-record.scm and copy the file > $PUB/lib/infinite-set-ADT-record.def to the same directory as that file. > > It seems that there is [no] file > $PUB/lib/infinite-set-ADT-record.def Sorry, this was my mistake. I have been attempting to get rid of the .def files, but missed this reference in the homework. The file you should start with for problem 13 is $PUB/lib/infinite-set-ADT-record.scm. I hope you have all seen that when you went looking for the nonexistent .def file. I have corrected the statement of homework 5. Sorry for any confusion. BTW, everyone, I'm back now and will be able to answer emails... Gary From leavens@cs.uiowa.edu Sun Nov 12 20:15:11 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 20:17:57 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: No.13 Hw5 Content-Type: text/plain; charset=us-ascii Zhen-fang Feng, Zhen-fang Feng wrote: > Hi, Gary, > > I send you a email yesterday about the file > $PUB/lib/infinite-set-ADT-record.def. Sorry I wasn't in email contact until just now; as I mentioned in class, I drove to Arkansas and back this weekend. > Actually I think I don't even need it at all now. Right. > When I first did this problem, I did not write the code in exactly the > order as you instructed in the file $PUB/lib/infinite-set-ADT-record.scm. > I got lots of errors, that's why I thought I might need the .def file. > > Anyway, I'm very curious why I got errors if I didn't write the code in > the order as you instructed. Is this a syntax requirement? I'm not sure what errors you had, but I'm guessing they were of the sort that you had unbound variables, some of them being the make- procedures generated by define-record. If that was the case then the reason you need to have the define-record before a define like (define inf-set-comprehend make-comprehended-set) is that before the define-record for comprehended-set is that until the define-record is executed, make-comprehended-set doesn't exist. This is a problem for any define that doesn't use a lambda expression. (Lambda expressions postpone evaluation of their bodies until the procedure is called, so they are relatively independent of the order of evaluation of the defines.) Gary From leavens@cs.uiowa.edu Sun Nov 12 21:25:50 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 21:28:41 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: "M. Allen" Subject: Re: 22C54 homework Content-Type: text/plain; charset=us-ascii Mark, "M. Allen" wrote: > professor leavens, > > ..i've been at a standstill on what is expected out of the > inf-set-member function.. ..it can't necessarily be traversed through by > a typcial procedural approach due to the possible infiniteness of > set.. Which version are you talking about? The procedural one (problem 12) or the transformation (problem 13)? You don't need to traverse the set at all for this problem. The predicate will decide for you whether something is in the set. > ..my difficulty has been with trying to find a way to check if a > 'type' fits the boundaries of a set.. ..please let me know if you can > help me see a clearer way to approach a solution.. You don't need to check whether something fits in the set or not. Your users will supply you with a predicate that does that. This is analogous to the infinite sequence problem. There we couldn't possibly traverse or construct an infinite list. But we didn't need to; all we get is a "rule" (a procedure) that generates a given element for us (in seq-generator). Gary From leavens@cs.uiowa.edu Sun Nov 12 21:35:23 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 21:38:08 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: HW5, problem 13 Content-Type: text/plain; charset=us-ascii Shawn, You're right. It's not just the code in inf-set-member? All the other code you have for problem 13 is wrong also. Shawn Garner wrote: > It can't be just the code in inf-set-member? because I comment it out and > get which I was getting before. I read the examples int the book. The > examples on the web and the ones we went over on that sheet. I understand > those ones just not how the variant-case fits into this problem. The way variant-case fits into the problem is that you will use it in inf-set-member, just like we used variant-case in the infinite-sequence example in the seq-nth procedure, and like we used variant-case in the ff example in apply-ff, and like we use variant-case in look-up in the phone-book example and like we use varinat-case in the road-map example in the roads-from procedure. Let's take the last one of these... ;;; $Id: road-map-as-record.scm,v 1.1 2000/11/07 04:20:21 leavens Exp $ ... (define roads-from (lambda (road-map place) (variant-case road-map (bare-earth () the-empty-set) ; copied from the procedural version (built-road (from to old-map) (cond ((eq? place from) (set-add to (roads-from old-map place))) ((eq? place to) (set-add from (roads-from old-map place))) (else (roads-from old-map place)))) (else (error "roads-from: should not happen"))))) See how, in the above code from the record version of the road map example, the body of the procedure starts with a variant-case. You will do the same thing. It has a case for each variant, as will your code. The body of each case is the code from the body of the returned procedure in the procedural version of the constructor operation that corresponds to that variant. For example, above, the code in the "bare-earth" case, the-empty-set is the body of the procedure returned by the bare-earth contructor in the procedural version ;;; $Id: road-map-as-proc.scm,v 1.1 2000/11/07 04:20:21 leavens Exp $ ... (define bare-earth (lambda (place) the-empty-set)) ; copied from here Now you find where in $PUB/lib/road-map-as-proc.scm the code for the other part of the variant-case in $PUB/lib/road-map-as-record.scm comes from. Gary From leavens@cs.uiowa.edu Sun Nov 12 21:53:33 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 21:56:22 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Matthew Philip Shera Subject: Re: probs with #13 and maybe #12 also Content-Type: text/plain; charset=us-ascii Matt, you wrote: > I'm having some trouble with #13 in that it won't type check. I followed > the procedural to record transformation exactly and I think that maybe my > problem is with how I implemented the procedural versions. I got #12 to > work OK, but maybe it was an accident, I guess. Anyway, the problem in > #13 is with the union, intersect and complement stuff. I get a message > that says "attempt to apply a non-procedure". My code for the procedural > implementation looks like this: > > (define inf-set-union > (lambda (set1 set2) > ([... I took out part of your code here...] (set1 z) (set2 z))))) > > have I done this incorrectly? If so, I realize you don't want to give > me the answer, but could you like clue me in somehow? When I use the body > of the interior lambda in the variant case for #13, that's when I get the > "attempt to apply a non-procedure" business. Thanks. I think the problem is that your code in the procedural version is written at the representation level. You may recall that in class we had to change to an abstract version to get seq-nth to work correctly. For example, when we wrote seq-add like: (define seq-add (lambda (s1 s2) (lambda (n) (+ (s1 n) (s2 n))))) that would have had the same problem in the transformation as you are having. The code above is not "abstract" because it assumes knowledge of the representation of the sequences s1 and s2. It will work in the procedural representation, but not when copied to the record rep. So we had to change it to the following to get it to be something that didn't assume knowledge of the details of sequences, so it would work when we copied it. (define seq-add (lambda (s1 s2) (lambda (n) (+ (seq-nth s1 n) (seq-nth s2 n))))) Hint hint. Gary From leavens@cs.uiowa.edu Sun Nov 12 22:19:16 2000 MIME-Version: 1.0 Date: Sun, 12 Nov 2000 22:21:51 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: HW5, problem 13 Content-Type: text/plain; charset=us-ascii Shawn, you wrote: > I see how you can use variant case with inf-set-member. > (deftype inf-set-member? (-> (T (inf-set T)) boolean)) > > But I don't see how to use variant case with the remaining 4 functions > Again I understand the example you put in the last email I just don't get > how to do this problem. > If you look at the examples on the web, you will see that variant-case is only used in the "observer" operation of the ADT. That is, you only use it in the procedure that "applies" the "function" that is the abstraction. For example, it's only used in seq-nth in the sequence example's record rep code, because that's the only operation that "applies" the sequence and so observes it. You can tell which operation (procedure) is like this from the types. A procedure that takes an argument of the ADT type but doesn't return that type is an observer. In problem 13, the only procedure like that is inf-set-member?. None of the other operations are like that. For them, you just have to build records to record the information (about the free variables that aren't globally-bound) so that the observer can use that. Does that help? Gary From leavens@cs.uiowa.edu Mon Nov 13 09:49:50 2000 MIME-Version: 1.0 Date: Mon, 13 Nov 2000 09:52:15 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: mbarnes@cs.uiowa.edu Subject: Re: Homework 5 # 8? Content-Type: text/plain; charset=us-ascii Michael, you wrote: > For problem #8, please clarify for me if you mean to have transparent > representations compared to opaque representations, or an ADT to a > non-ADT, or something else? def: a type is *opaque* if there is no way to find out its rep, even by printing otherwise it is transparent. From leavens@cs.uiowa.edu Mon Nov 13 12:03:01 2000 MIME-Version: 1.0 Date: Mon, 13 Nov 2000 12:03:19 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Li Tang Subject: Re: homework 5, problem 10 Content-Type: text/plain; charset=us-ascii Li, you wrote: > Hi Gary, > Hw5.10 > How do I represent {}* in define-record-type. > Is it OK? > (define-record-type begin command > ((com command) ..)) Not really. You should use a list in the abstract syntax when there is a * or + in the grammar. > Do I need write define-record-type and define-record > for ::=|(-) ? Yes. -- Gary From leavens@cs.uiowa.edu Mon Nov 13 13:09:40 2000 MIME-Version: 1.0 Date: Mon, 13 Nov 2000 13:09:34 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: xiaolin sun Subject: Re: Xioaolin Sun: question about Q10 of hw5 Content-Type: text/plain; charset=us-ascii Xiaolin, xiaolin sun wrote: > Hi, Gary, > > I am having a question about Q10 of hw5: How we deal > with a sybol in its grammar? for expamle, > > for " command ::= := " > > we are asked to define its define-record-type and > define-record like: > ======================================== > (define-record-type equal command > ((var symbo) (':= symbol) (e expr))) > ======================================== > (define-record equal (var ':= e)) > ======================================== > > my problem is : is (':= symbol) necessary? or just > skip it since it's not a variable. You should leave out := from the abstract syntax, since it's punctuation. That is, it doesn't convey any information over and above the name "equal" you've chosen for the record, so it's not useful to include it. -- Gary From leavens@cs.uiowa.edu Sun Nov 26 17:21:50 2000 MIME-Version: 1.0 Date: Sun, 26 Nov 2000 17:24:40 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Matthew Philip Shera Subject: Re: hw5 prob 29 Content-Type: text/plain; charset=us-ascii Matt, you wrote: > Hi Gary. I'm a little confused with the procedural rep. I can't seem to > figure out how to do the update procedure. It's supposed to return a > (maybe T), but I'm not understanding how the (store T) stores the > location. Can you help me without giving me the answer? Thanks. One hint is to think of inverting procedural to record rep transformation. That is, if you've done problem 28, you can copy code from the variant-case. Another is to think about the representation, in the procedural rep, you need to return a closure that takes a number as an argument (and returns a (maybe T)). That closure takes the same argument as the record would have stored in problem 28... Gary From leavens@cs.uiowa.edu Sun Nov 26 19:35:30 2000 MIME-Version: 1.0 Date: Sun, 26 Nov 2000 19:38:20 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: mbarnes@cs.uiowa.edu Subject: Re: opaque? Content-Type: text/plain; charset=us-ascii Michael, mbarnes@cs.uiowa.edu wrote: > I would like you to clarify a point regarding the opaqueness of a type. > The given definition is "it cannot be exposed by any operation (including > printing). > > In using a message rep and a store is printed the type can be determined > by analyzing the code, but it is not exposed explicitly, like for the > record rep. So, does the message rep meet the definition of opaqueness? > > I know you can't answer that, but can you clarify the definition to > explain whether the rep must be explicitly exposed by printing, or can be > determined by analyzing the code. The definition I gave assumes that the body of a procedure isn't printed. If there's no use you can make of the information printed, to change or affect the representation, then I think you should count it as opaque. Gary From leavens@cs.uiowa.edu Sun Nov 26 19:37:39 2000 MIME-Version: 1.0 Date: Sun, 26 Nov 2000 19:40:30 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: mbarnes@cs.uiowa.edu Subject: Re: ?? "store-message-rep.scm", line 1: unbound variable: Content-Type: text/plain; charset=us-ascii Michael, mbarnes@cs.uiowa.edu wrote: > Is this error message important? The program seems to work fine in spite > of it. Can you please explain it? > > > (load "store-message-rep") > "store-message-rep.scm", line 1: unbound variable: > ; in expression: > ; in top level environment. > > This sounds like you have a character in your file (on line 1 I guess), that doesn't print, so you can't see it, but that SCM is counting as a variable. I think it takes a fairly liberal view of characters... Try deleting that line and retyping it. But if the program works fine otherwise there is really no need. Gary From leavens@cs.uiowa.edu Sun Nov 26 23:44:36 2000 MIME-Version: 1.0 Date: Sun, 26 Nov 2000 23:47:24 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: xiaolin sun Subject: Re: Xiaolin Sun: need your help on Q30 Content-Type: text/plain; charset=us-ascii Xiaolin, The problem is that in the update! case you have no side effects. So the object, store-1, can't ever change its state. Thus the initial tests that expect an empty store work, but not later ones. Gary From leavens@cs.uiowa.edu Mon Nov 27 13:12:53 2000 MIME-Version: 1.0 Date: Mon, 27 Nov 2000 13:13:19 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: leavens@cs.iastate.edu Subject: message representation in HW5 Content-Type: multipart/mixed; boundary="------------137E15E730E4E4F0A7D4E66E" >From leavens Mon Nov 27 11:49:36 2000 Date: Mon, 27 Nov 2000 11:50:04 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Matthew Philip Shera Subject: Re: message representation Content-Type: text/plain; charset=us-ascii X-Mozilla-Status2: 00000000 Matt, Matthew Philip Shera wrote: > Hi again. I'm having problems with this. I chose to use a list as the > internal data structure and chose to do a list of lists like this: ((0 12) > (5 15)) > > So in my code, when trying to do the fetch and defined? procedures, I am > trying to do recursion. Is this the wrong approach? You can do that. But you will have to use letrec or another helping procedure to write these recursions over lists. You can't get the object's procedure to do the recursion (at least not easily) ... Gary -- Gary  -=- MIME -=-  This is a multi-part message in MIME format. --------------137E15E730E4E4F0A7D4E66E Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit --------------137E15E730E4E4F0A7D4E66E Content-Type: message/rfc822 Content-Transfer-Encoding: 7bit Content-Disposition: inline >From leavens Mon Nov 27 11:49:36 2000 Received: from cs.uiowa.edu (dhcp206.divms.uiowa.edu [128.255.28.195]) by server.divms.uiowa.edu with id LAA22241; Mon, 27 Nov 2000 11:49:35 -0600 (CST) Message-ID: <3A229ECC.6165300@cs.uiowa.edu> Date: Mon, 27 Nov 2000 11:50:04 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Matthew Philip Shera Subject: Re: message representation References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mozilla-Status2: 00000000 Matt, Matthew Philip Shera wrote: > Hi again. I'm having problems with this. I chose to use a list as the > internal data structure and chose to do a list of lists like this: ((0 12) > (5 15)) > > So in my code, when trying to do the fetch and defined? procedures, I am > trying to do recursion. Is this the wrong approach? You can do that. But you will have to use letrec or another helping procedure to write these recursions over lists. You can't get the object's procedure to do the recursion (at least not easily) ... Gary -- Gary --------------137E15E730E4E4F0A7D4E66E-- From leavens@cs.uiowa.edu Mon Nov 27 19:51:26 2000 MIME-Version: 1.0 Date: Mon, 27 Nov 2000 19:54:26 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: HW5 problem 28 Content-Type: text/plain; charset=us-ascii Shawn, First, you shouldn't use eq? to compare numbers in Scheme, but that isn't your problem. The problem is in the false part of the fetch procedure. Look at the record definitions. See where they are recursive. Your code for fetch should also be recursive in the same way. you wrote: > Can you give me some help with problem 28. ... Gary From leavens@cs.uiowa.edu Mon Nov 27 23:09:57 2000 MIME-Version: 1.0 Date: Mon, 27 Nov 2000 23:13:10 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: HW5, problem 30 Content-Type: text/plain; charset=us-ascii Shawn, Shawn Garner wrote: > you said for problem 30 that we have to write > adt that responds to > update! > fetch > defined-in-store > > but isn't all the work really done in create-empty-store? In a sense. Think of create-empty-store as the class "constructor", which creates an object. But you also have to program the "instance operations", which are the ones named above. > should I reuse the code from 28 and 29 or just start over? You can certainly reuse the code from problem 28 or 29. I think it is easiest (conceptually) to reuse the code from problem 28; but which ever works for you. You can also use a completely new data structure if you feel like doing more coding :-). Gary From leavens@cs.uiowa.edu Wed Nov 29 10:02:53 2000 MIME-Version: 1.0 Date: Wed, 29 Nov 2000 10:02:10 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: HW5 problem 30 Content-Type: text/plain; charset=us-ascii Zhen-fang, you wrote: > Hi, Gary, > > Could you take a look at the attached file for me? I couldn't fix the > update!. Thanks. Your code is fine, but you are using eq? to compare numbers, which you should not do. That causes the following test case to fail. (something->value (send store-1 'fetch 3001001001)) "d:/classes/ui54/homework/current/hw5.tst/store-message-rep.tst", line 71: ERROR: something->value passed nothing Gary From leavens@cs.uiowa.edu Thu Nov 30 15:03:57 2000 MIME-Version: 1.0 Date: Thu, 30 Nov 2000 15:05:23 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Matthew Philip Shera Subject: Re: homework6 Content-Type: text/plain; charset=us-ascii Matt, you wrote: > A question about extending the interpreter to handle > lists: Do we want to add the list procedures to the prim-ops, or should we > define a whole new procedure, say apply-list, which is in the spirit of > apply-proc? Or maybe we can do it either way??? thanks You should add the list procedures as primitive operations (as prim-ops in the inital environment, init-env). Gary From leavens@cs.uiowa.edu Fri Dec 1 22:53:18 2000 MIME-Version: 1.0 Date: Fri, 01 Dec 2000 22:56:34 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Matthew Philip Shera Subject: Re: list ops, homework 6, problem 5 Content-Type: text/plain; charset=us-ascii Matt, You described your problem getting the code for cons in apply-prim-op to type check. > the call to cons to return a pair of expressed-values, and it won't type > check... What should I do? Thanks. In the code for apply-prim-op's case for cons, you will need to use both expressed->list to make the second argument to cons into a list (to make Scheme's cons happy with the type of its second argument), and you'll need to use list->expressed on the result (to make the result into an expressed value, to make apply-prim-op have the right type). Gary From leavens@cs.uiowa.edu Sat Dec 2 16:33:19 2000 MIME-Version: 1.0 Date: Sat, 02 Dec 2000 16:36:39 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Xiaoding Luo Subject: Re: HW6, problem 12 Content-Type: text/plain; charset=us-ascii Xiaoding Luo you wrote: > Hi, Gary, I have a question on hw12. should the max we write work in > the expression > (run "let max = ..... > in max(1,72,max(5,max(2,50,78,82)))") ? no > if that is the case, it seems we need a procedure in defined > language that takes unspecified number of arguments whose equavelent in > scheme looks like (lambda args (....)). we might also need letrec in > defined language. or we just need simply write different max in defferent > expressions? According to the homework, you are supposed to write max so it works with exactly 3 arguments, no more, and no less: "... which computes the maximum of 3 numeric arguments, in the defined language." Gary From leavens@cs.uiowa.edu Sat Dec 2 19:17:56 2000 MIME-Version: 1.0 Date: Sat, 02 Dec 2000 19:21:17 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: LiTang Subject: Re: Content-Type: text/plain; charset=us-ascii Li, you wrote: > Hello Gary, > hw6.4.b used read-eval-print > How do I test "add1"? I tried "add1(7);", I got error message. Hmm. It works for me in the interactive loop... --> add1(7); 8 and with run you don't put the semicolon in... > (run "add1(7)") 8 If you put the semicolon in with run, you'll get an error like this: > (run "add1(7);") ERROR: Tokens left over: (#(token semicolon *) #(token end-marker *)) Gary From leavens@cs.uiowa.edu Sat Dec 2 22:34:16 2000 MIME-Version: 1.0 Date: Sat, 02 Dec 2000 22:37:35 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: LiTang Subject: Re: HW6, problem 5 Content-Type: text/plain; charset=us-ascii Li, you wrote: > Hello Gary, > typed> (run "emptylist") > #(prim-proc emptylist) : expressed-value > > I got this message, is this correct? No, it should be (). This should be like the way we added the defined name zero with value 0 in class. Gary From leavens@cs.uiowa.edu Sun Dec 3 11:30:39 2000 MIME-Version: 1.0 Date: Sun, 03 Dec 2000 11:33:59 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Paul Scott Subject: Re: hwk 6, problem 5 Content-Type: text/plain; charset=us-ascii Paul, Paul Scott wrote: > Hi, this is Paul Scott. > > Do you know what is wrong if the error it gives me for problem #5 says: > "ERROR: list: end of file in"? That means you are missing a right parenthesis. If you use the new type checker (newscm54), you will perhaps get a line number where the problem is. But in any case, that (or missing double quote) is almost certainly the problem. > Also, for car and list, etc, how do I check to make sure it is a number or a > list, so I can change it from expressed to number, or expressed to list, and > back? Because it seems like I have to know if it is a number or list in the > first place so I can change it to a number or list so the scheme procedures > of car, list, etc. can work on it. The procedures in $PUB/lib/ch5-1-4-expressed-value.scm will do these for you. For example, the procedure expressed->number both checks that its argument expresed-value is a number (and issues an error message if it isn't) and will convert the argument from an expressed-value to a the type number if it is. Since what apply-prim-op gets are lists of expresed-values, this checking is just what you will need. Then, for example, when you do some arithmetic on numbers, you know from Scheme that the result will be a number, so you can use number->expressed to change the type of the result to expressed-value. As I demonstrated in class, and you can see, for example, in ch5-1.scm, the primitive operations just try to convert the arguments to the right types, without checking them first. Don't worry about issuing nice error messages. Gary From leavens@cs.uiowa.edu Sun Dec 3 11:36:44 2000 MIME-Version: 1.0 Date: Sun, 03 Dec 2000 11:40:05 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: HW6, problems 7 and 5 Content-Type: text/plain; charset=us-ascii Zhen-fang Feng, you wrote: > Hi, Gary, > Thanks for your email. It's helpful. But I still couldn't figure out how > to do the problem NO.7 without also using "=" and "in." This is a misunderstanding of the problem. You can use "=" and "in" of course. I have reworded problem 7 as follows: 7. (10 points) [calculate 3**8] Write an expression in the defined language to calculate 3**8, that is 3 to the eighth power, using only let, (and the rest of let's syntax: = and in), *, variable names, and the number 3. See above for how to run the interpreter. Hand in a transcript showing that your expression works. > I also have a question for problem NO.5. Why is the following expression > not correct for "emptylist" case? > ((emptylist) (list->expressed '())) Do you mean as part of apply-prim-op? The reason that isn't correct is that emptylist is not a primitive operation, but a constant. You have to define it in init-env the way we defined zero to be 0 in class. Gary From leavens@cs.uiowa.edu Sun Dec 3 18:52:08 2000 MIME-Version: 1.0 Date: Sun, 03 Dec 2000 18:55:27 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Paul Scott Subject: Re: HW6, problem #5 Content-Type: text/plain; charset=us-ascii Paul, Paul Scott wrote: > Hi this is Paul Scott again. How do I make the empty-list be part of the > environment if there is no way to make the empty list (a list of t's) into > an expressed or denoted value? Yes, there is. You can use list->expressed and list->denoted in ch5-1-4-expressed.scm and ch5-1-4-denoted.scm. Gary From leavens@cs.uiowa.edu Sun Dec 3 22:32:26 2000 MIME-Version: 1.0 Date: Sun, 03 Dec 2000 22:35:46 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: mbarnes@cs.uiowa.edu CC: leavens@cs.iastate.edu, Matt Shera Subject: Re: HW6, Prob 13 Content-Type: text/plain; charset=us-ascii Michael, you wrote: > On problem 13, I think I have procedure-as-closure.scm figured out (it > typechecks anyway) but I'm stuck with the "redefine init-env so that it > contains Scheme closures" part. I can't figure out what to add to > init-env that would be related to closure. Matt, you wrote: > Whatever in the world are we supposed to be doing when we are supposed to > be extending the init-env to support closures??? I am at a total loss. I > think I have the other part (the record to procedure transformation) > correct, but can't test it until I get this other part done. > If you have procedure-as-closure done, then you have defined make-prim-proc to make Scheme-closures. So in the your file for the solution that loads procedure-as-closure.scm, pretty much the same code that worked before to define init-env should work with the new definition of make-prim-proc. Indeed, there shouldn't be much difference between the old code for defining init-env and the new code, since we've just changed the representation of procedures (hint, hint). Gary From leavens@cs.uiowa.edu Mon Dec 4 10:25:17 2000 MIME-Version: 1.0 Date: Mon, 04 Dec 2000 10:27:09 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Paul Scott Subject: Re: HW6, #5 Content-Type: text/plain; charset=us-ascii Paul, Paul Scott wrote: > Hi this is Paul Scott again. How do I make the empty-list be part of the > environment if there is no way to make the empty list (a list of t's) into > an expressed or denoted value? There is a way to do that. Use list->expressed and list->denoted from, respectively, ch5-1-4-expressed.scm and ch5-1-4-denoted.scm. The problem says to use the helpers in those files. -- Gary From leavens@cs.uiowa.edu Mon Nov 27 19:51:26 2000 MIME-Version: 1.0 Date: Mon, 27 Nov 2000 19:54:26 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: HW5 problem 28 Content-Type: text/plain; charset=us-ascii Shawn, First, you shouldn't use eq? to compare numbers in Scheme, but that isn't your problem. The problem is in the false part of the fetch procedure. Look at the record definitions. See where they are recursive. Your code for fetch should also be recursive in the same way. you wrote: > Can you give me some help with problem 28. ... Gary From leavens@cs.uiowa.edu Mon Dec 4 11:55:36 2000 MIME-Version: 1.0 Date: Mon, 04 Dec 2000 11:57:36 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Li Tang Subject: Re: Content-Type: text/plain; charset=us-ascii Li, Li Tang wrote: > Hi Gary, > In ch5-4.scm, I didn't fine any place call init-env, so I'm confused. > Why should we need to use it? The init-env is used by the read-eval-print loop, which passes init-env to the first call to eval-exp. See $PUB/lib/rep.scm. Also run uses it, see $PUB/lib/run.scm. Gary From leavens@cs.uiowa.edu Mon Dec 4 14:47:01 2000 MIME-Version: 1.0 Date: Mon, 04 Dec 2000 14:48:56 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Zhen-fang Feng Subject: Re: HW6, problems 13 Content-Type: text/plain; charset=us-ascii Zhen-fang Feng wrote: > Hi, Gary, > > I finally find the errors. Because I did not load the files in > the correct order as you indicated in the homework. This is the way I load > the files, > > (load-quietly-from-lib "ch5-4-2-denoted-value.scm") > (load-quietly-from-lib "ch5-4-2-expressed-value.scm") > (load-from-lib "ch5-4.scm") > (load "procedure-as-closure.scm") > > Why does this matter? Thanks. The reason this matters is that the second of two definitions acts like a set! and replaces the binding that a name previously had. For example, if you do a second define of init-env, it replaces the value that init-env originally had. See the Revised 5 Report on Scheme (from the course web page) for more about define, or look in exercise 5.5.5. Gary -- Gary From leavens@cs.uiowa.edu Sun Dec 10 21:14:21 2000 MIME-Version: 1.0 Date: Sun, 10 Dec 2000 21:17:53 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: xiaolin sun Subject: Re: Xiaolin: questions abou the exam Content-Type: text/plain; charset=us-ascii Xiaolin, xiaolin sun wrote: > Hi, Gary, > > Sorry to bother you on the weekend! > no problem. > > I am having a question about the example you gave us > on the Wedenesday's review class. > > ==================================== > > ::= when do > ===================================== > > (define-record-type when-exp parsed-exp((......))) > > ======================================= > (define eval-exp > (lambda (exp env) > (variant-case exp > (when-exp (test-exp body) > (if(true-value? (eval-exp test-exp env)) > (ignore (eval-exp body env)); ?? > (number->expressed 0))) > ;same as the result of ignore? > ..... ; other case > > ;Also you gave us the help procedure > > (define ignore > (lambda (ev) > (number->expressed 0))) ; same as "false" > case? > ======================================== > > I am confused about the ignore's purpose, since after > the operation of "true-value? " the true and false > case are same. I think I lost sth you talked about, > thank you for your reply! The idea is a fairly fine point of langauge design. Do we want the result of the body of the when to be the result of the expression as a whole when the test is true, or do we want to have when expressions be executed purely for side effects. The latter is more strict, and resembles the way that the type checker I wrote for Scheme works. But I actually think the former is more natural for an expression langauge, like the defined language. However, if you want to make when expressions be executed purely for side effects, then you need some way for the semantics to "throw away" the value of the body, which is what ignore does. > > > ========================================= > By the way, I am doing the old exam (Fall,1995), how I > handle the case "do-exp" ? the grammar as follows: > > ::= do until > ::= > ========================================== This would be similar to the for loop example we did in class. That means, by the way, that we won't have a problem like it on the test, as we don't have assignment (section 5.5), which is needed for loops like this to make sense. But in essence, you write a helping procedure (perhaps in a letrec) that evaluates the body, then does the test, if the test comes out false, then you loop again. Gary From leavens@cs.uiowa.edu Sun Dec 10 21:51:55 2000 MIME-Version: 1.0 Date: Sun, 10 Dec 2000 21:55:26 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: xiaolin sun Subject: Re: Xiaolin: still confused about when expressions Content-Type: text/plain; charset=us-ascii Xiaolin, xiaolin sun wrote: > Hi, Gary, > > Thank you very much for you quick reply! > I am embarrassed that I am still a little confused to > this problem. let we suppose we delete the " ignore", > what happend? I mean just do: > > (if (true-value?.......)) > (eval-exp body env) ; delete ignore > (number->expressed 0))) This is sensible, and is the other althernative semantics I described in my email. When you do that, then the result of the when expression is the result of the body, when the test is true. I think it would have been better if I'd never mentioned the alternative :-), sorry for any confusion. Gary From leavens@cs.uiowa.edu Mon Dec 11 10:44:53 2000 MIME-Version: 1.0 Date: Mon, 11 Dec 2000 10:48:24 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: ignore in ::= when do Content-Type: text/plain; charset=us-ascii Zhen-fang Feng, you wrote: > Hi, Gary, > > I've read the Q&A on ignore in ::= when do in the > Q&A page. I'm still not clear about your explaination. What do you mean by > saying "make when expressions be executed purely for side effects?" From > the grammar, it does not make sense to me to "throw away" the value of the > body. In a language without side-effects, such as the one in section 5.4, I agree. But once you have side effects as in section 5.5, it would make sense... Gary