From leavens@cs.uiowa.edu Thu Oct 12 17:31:13 2000 MIME-Version: 1.0 Date: Thu, 12 Oct 2000 17:32:17 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Thuy-tien T Pham Subject: Re: Question on hw 3, problem 1a Content-Type: text/plain; charset=us-ascii Thuy-tien, Thuy-tien T Pham wrote: > I am working on hw3 and unsure if I am on the right track or not. Will > you look over the code below and let me know if I doing it right or not? > this is number 1a. > > (define mvar > (make-varref 'x)) ==> x This is right, as is what you wrote for the second expression. However, > (cons mvar(cons mq '())) ==> (x (quote y)) Is not right. You should use make-app instead of cons. What you did won't type check as a bexp. > I am not sure if I can use the '() or not. Don't, unless you want to make a list. Hope that helps, -- Gary From leavens@cs.uiowa.edu Mon Oct 16 23:24:35 2000 MIME-Version: 1.0 Date: Mon, 16 Oct 2000 23:25:47 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Heath CC: Yan Liu Subject: Re: Type Checking Errors Content-Type: text/plain; charset=us-ascii Heath wrote: > Yan, These are very similar type check errors that I've strugled > with through the first assignment, do you have any suggestions? > Should I be making more cast's or something? Here's my code and the > errors... *****FREE-VARS***** ---CODE--- > (load-from-lib "lambda-1+quote.scm") (deftype free-vars (-> > (lambda-1+quote-exp) (set symbol))) > (define free-vars > (lambda (expr) > (cond > ((varref? expr) (set-of expr)) > ((lambda? expr) (... > (set-of (lambda->formal expr)))) > (else ...))))) > ---ERROR--- > Error: Operator type and argument types do not match in: (set-of > (lambda->formal > expr)) > Operator type : (-> (lambda-1+quote-exp) t) > Argument type list: (symbol) > Error: Definition does not match declared type (with deftype) for: > free-vars > Expected (declared) type: (-> (lambda-1+quote-exp) (list symbol)) > Inferred type : (-> (lambda-1+quote-exp) (list > lambda-1+quote-exp)) > *****FREE?***** The problem is actually in a different spot. In the varref case, you have the result "(set-of expr)", and "expr" has type lambda-1+quote-exp. So the type checker thinks you want to return a set of lambda-1-+quote-exp objects. Then it complains about the (correct) code in the next case, because the type being returned there doesn't match... > > > ---CODE--- > (load-from-lib "lambda-1+quote.scm") > > (deftype free? (-> (symbol lambda-1+quote-exp) boolean)) > (define free? > (lambda (s expr) > (cond > ((varref? expr) (eq? s expr)) > (...)))) > ---ERROR--- > Error: Definition does not match declared type (with deftype) for: > free? > Expected (declared) type: (-> (symbol lambda-1+quote-exp) boolean) > Inferred type : (-> (lambda-1+quote-exp > lambda-1+quote-exp) > boolean The problem here is the same in some sense. In the base case, you are comparing s and expr using (eq? s expr). The type checker thinks that the arguments to eq? should have the same type. Since it has guessed that the type of expr is lambda-1+quote-exp, from the preceeding expression (varref? expr), it guesses that s has type lambda-1+quote-exp. Then it complains that this doesn't match the defined type. -- Gary ____________NetZero Free Internet Access and Email_________ Download Now http://www.netzero.net/download/index.html Request a CDROM 1-800-333-3633 ___________________________________________________________ From leavens@cs.uiowa.edu Wed Oct 18 18:24:46 2000 MIME-Version: 1.0 Date: Wed, 18 Oct 2000 18:26:10 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en To: Mike Scott Bealer Subject: problems in HW3, number 11 Content-Type: text/plain; charset=us-ascii Mike, Mike Scott Bealer wrote: > Prof Leavens, > Could you help me please? This file won't type check and I can't figure > out why. The checker claims my 'if arms' are of type symbol, but I'm sure > they're of type number. Please help - this has caused me hours of > trouble. Thanks, Both of the problems are coming from a different place in your code. For example, the following problem: Error: Arms of if expression have different types Left arm: (which-pos x 0 (car lolos)) Right arm: (get-pos-depth x (cdr lolos)) Left arm's type: number Right arm's type: symbol is actually coming from the procedure below. (define lexical-address-of-varref (lambda (x lolos) (list (string->symbol "(") x (string->symbol ":") (get-depth x 0 lolos)(get-pos-depth x lolos) (string->symbol ")")))) In the procedure above, the arguments passed to the procedure list are symbols, at least the first three are. That's enough to the type checker to conclude that they should all be symbols. This makes the type checker inferred that the result type of the procedures get-depth and get-pos-depth are symbols. This is why the right arms type is reported a symbol, because that is the return type inferred for get-pos-depth. If you were correctly using the procedure make-lexical-addr instead of what you are doing, this would not have happened, because that procedure takes a symbol and two numbers as arguments. Of course, the code for lexical-address-of-varref is more complicated than just a simple call to the procedure, but it does boil down to that at the end. You should probably never use something like (string->symbol "(") in your code for this class. Hope that's helpful. Gary _____NetZero Free Internet Access and Email______ http://www.netzero.net/download/index.html From leavens@cs.uiowa.edu Sat Oct 21 13:56:01 2000 MIME-Version: 1.0 Date: Sat, 21 Oct 2000 14:00:14 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Yan Liu , Gary Leavens , Mark Allen , Michael Barnes , Mike Bealer , Zhen-Fang Feng , Shawn Garner , Jihyun Han , 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: summary and responses to the course feedback for 22C:54 Content-Type: text/plain; charset=us-ascii Hi, First, thanks for all the feedback that you gave me. I think I have learned something from it, which will be valuable in improving the course for you. You can see the details and what I have included below. This is also available in $PUB/docs/feedback.txt and on the Web. Gary The following is my summary, organization, and slight paraphrase, with responses, of your feedback on the course. I have organized it topically. Comments about things I should start doing are marked with a +, comments about things I should stop doing are marked with a -, and comments about things I should continue doing are marked with an =. Unary numbers like (IIII) at the end are my count of how many times a comment (or similar enough) comment was given. My responses are enclosed in brackets. Homework Length/time - stop giving such long and time-consuming homework IIIII III - stop giving us so little time for the homework II + have some parts of the homework due each class period, so that we could have more feedback, faster - the homework is too long for the number of credit hours of the class (# hours of homework plus reading per week should equal the number of credit hours of the class) II (one student added that they felt they are learning from the assignments, however) + explain more about what you want for the answers [Clearly the length and time needed for the homework is one of the major concerns of many students. The students who believe that the number of hours spent in homework and reading should equal the number of credit hours for the class are, I believe, mistaken. I think it is supposed to be something like a factor of two or three times the number of credit hours. It seems to me, however, that the major difficulty has to do with the examples, or rather lack of them. This makes some sense to me, as I have previously run this kind of course with an attached discussion section that would give more examples, explanation, and direction for doing the homeworks. I will make every attempt to make a more examples available to you. That said, I will try to be vigilant in making sure that the homework does not contain problems of undue length, complexity, and that all the problems are relevant. I try to explain clearly what I'm looking for with regard to answers on the homework; I think the best remedy for this is for you to read the homework early on, and send me an e-mail if there is something unclear about it.] Difficulty/examples + give easier homework problems that do not have so many points each - stop giving questions that are too complicated/hard/condensed III + give better examples before we do the homework; sometimes we don't have any idea how to start IIIII I + give more realistic, difficult examples in class that correspond more closely to the homework, with complete solutions posted on the Web (you don't need to get over them in class) += start/continue giving out homework solutions or explanations for the answer to the homework. II + you don't need [to] give us in the homework solutions,... but you could go through them with us = continue the great homework problems [The lexical address problem is probably the most difficult problem of the entire semester, from past experience. However, I think it is valuable for integrating a number of techniques and ideas. We will have some other problems that are worth many points, because they are also long and involve quite important ideas. The problems in the first few homeworks were, in some sense, warmup problems. I rather like problems that integrate material, because they are a good way to learn. I have every confidence that you can think about and learn the material. But again,I will try to be vigilant in making sure that the homework does not contain problems of undue length, complexity, and that all the problems are relevant. The complaints about needing more, better examples were a surprise to me, and probably the thing I have learned most from this feedback. I will make every attempt to make a more examples available to you. My first thoughts are to make some of the programs in the book available with our typed notations. I guess I should also mail out solutions to homework problems that are past more aggressively (I had been waiting until someone asked me for something.) I also try to make up examples for lecture, and these are usually made available both in the lecture directory and in the library. If I forget but one in the library, you can look in the lecture notes directory as well. However, it's difficult to treat really complicated examples in class itself. If you have more specific suggestions, that would be valuable for me. I'm quite happy to go over homework solutions during class, don't hesitate to ask. Sometimes I feel that some students would like to know answers but are afraid to ask.] Other -stop having such weird names for files and data types, i.e. lambda-1+exp, instead of l1exp -stop using such long names -stop making us handwrite things first [Some of the names for grammars are historical, and I apologize for their length. In my defense, I think that some of these may be easier to remember than shorter condensed names. I do not plan to keep the the practice of having you handwrite homework assignments as a general rule. I wanted to make sure that everyone had a some exposure to this technique. If you find it is useful, you can continue using it on your own.] Tests = continue giving more time on the exams + = start/continue giving solutions to previous exam problems [I do plan to continue these practices.] Course content, topics Speed - may be slow down a bit [in the speed of covering topics] + spend more time covering material instead of rushing through it; take time to do the examples [There is always some tension between covering material and making sure that everyone has time to understand it. I'm pleased that this was not a major issue, which tells me that I'm striking somewhat of an appropriate balance. I would like to make sure that we get to some of the later material on interpreters and parameter passing, if not object-oriented languages, otherwise what we're doing so far in class will not be as valuable for you.] Topics + give practical uses for what we are learning; why is it important? What are the uses? + introduce more languages into the class. While scheme is "fun" it is sometimes harder to [code in] than other more "standard" languages. [While these are not major issues (i.e., not for a lot of students), apparently, they are important comments. A class like this has a choice of covering several languages somewhat superficially to achieve more breath of concept coverage, or of covering their concepts in more depth. I believe it's valuable to cover fewer concepts in more depth for several reasons. First, because most of you have experience in Java (or C++) you are already familiar with the other major paradigm in programming languages. The third most interesting paradigm, that of logic programming, requires many of the same techniques as functional programming, and some understanding of backtracking, continuations, and logic, that follow from the topics that we are studying. Second, there is much anecdotal and some empirical evidence that learning several different kinds of languages helps make one a more expert programmer. For example, at the object-oriented conference I was at last week, one object-oriented researcher on a panel urged the audience to learn about functional programming. The theory is that the learning these other ideas gives you more ways to approach a problem solutions. I think that really digging into a language like Scheme is much better for broadening ones thinking than just doing a few small problems in it. Even if you decide that you don't like functional programming as a standard way of programming, you'll be able to reject it from a deeper knowledge instead of just a passing acquaintance. But with this deeper knowledge, comes several techniques and ideas that I hope will be valuable in your future work: the ideas of induction, recursion, and the correspondence of the input data to the structure of a program, are some of the most obvious. I think you'll also find the concepts of programming languages themselves quite useful, such as free and bound variables, static properties as opposed to dynamic properties, parts of languages (means of computation, combination, and abstraction), the idea of syntax abstraction (syntactic sugar), and other ideas will learn later in the semester. I think that Scheme, like all programming languages, is well-suited for solving some kinds of problems, and more difficult for others. Scheme seems to be good for writing programming language interpreters, which is one of the main reasons we are using it (although similar functional languages would do as well, or better). Learning a new language is going to be more difficult than continuing in a language you already know. It will expose you to different problems than those you are used to. When you are in such situations, you cannot use your "compiled" knowledge of previous problem solutions to react quickly. This makes things difficult. That's you'll find that as the course goes on, some things that were difficult at the beginning become "compiled" knowledge, that you can draw on to quickly solve such problems. I hope that recursion over flat lists is becoming that way for you now. This is the major justification for learning new programming paradigms, because the more kinds of "compiled" knowledge you have, the more problem/programming situations you can react to quickly, like an expert.] Classroom = being enthusiastic in class = explaining things and giving examples (e.g., on lexical depth) . IIII = in class exercises = continue taking the way he is now, it's perfect! = continue smiling = I like the handout for recursions/tail recursion, keep handing these out. [I do plan to continue these practices.] Other = I like the way Gary answers my course questions; and for example he always responds to my e-mail very quickly. + go to lab and work; it is too hot there [I do try to respond to e-mail quickly. Thanks. Which lab room in particular are you talking about? It would probably be quicker to complain directly to the department chair or the system support people.] From leavens@cs.uiowa.edu Tue Oct 24 22:06:12 2000 MIME-Version: 1.0 Date: Tue, 24 Oct 2000 22:10:28 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Xiaoding Luo Subject: Re: HW4, problem 5, type of cond->clauses Content-Type: text/plain; charset=us-ascii Xiaoding, Xiaoding Luo wrote: > Hi, Gary, why the deftype of cond->clauses is > (-> (lambda-cond-letrec-exp) (list (cond-clause lambda-cond-letrec-exp))) > > instead of being (-> (lambda-cond-letrec-exp) (list cond-clause)) ? > > this is for question desugar-cond. Good question. The type cond-clause is a type constructor, like "list", "vector", or "set". It is a type constructor because it contains expressions. The analogy is that list is a type constructor, since a (list T) object contains objects of type T; similarly, a (cond-clause T) object contains objects, i.e., expressions, of type T. One benefit of this is that the cond clause helpers work for all different kinds of grammars: we don't need separate helpers for each grammar that uses them. You might also just look at the types of the helpers in $PUB/lib/cond-clause.scm. Gary From leavens@cs.iastate.edu Thu Oct 26 14:07:55 2000 Date: Thu, 26 Oct 2000 14:07:48 -0500 (CDT) From: "Gary T. Leavens" To: leavens@cs.iastate.edu Reply-To: leavens@cs.uiowa.edu Subject: working with the type decl From: "Gary T. Leavens" X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Shawn, I don't see what your procedure decls->decls-list is doing, or is supposed to do. The type (decl lambda-if-let-exp) is the type of a declaration, and "decl" is a type constructor, so you shouldn't try to convert a list of (decl lambda-if-let-exp) into a list of decl; that makes no sense. It is, in any case, the source of many type errors. You should look at $PUB/lib/decl.scm and use the helpers there to process declarations; don't use car and cdr to work with them. Similarly, your procedure decls->exp-list should also use the decl helpers in $PUB/lib/decl.scm. Take a look at the example I put up in $PUB/lib/lambda-if-let-examples.scm, in particular at the procedure decls->vars, for an example of how to work with the decl helpers. If there's a specific error message you don't understand, send that along too, please... but I think this is the main problem with the code you sent. Gary From leavens@cs.uiowa.edu Sat Oct 28 17:03:39 2000 MIME-Version: 1.0 Date: Sat, 28 Oct 2000 17:06:30 -0500 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Mike Scott Bealer Subject: Re: working with sets and lists in free-vars Content-Type: text/plain; charset=us-ascii Mike, you wrote: > Prof Leavens, > > I can't get my free-vars over letrecs to type-check! I've attached the > file, could you please give me some suggestions? There are two problems in your code. One is that you aren't using set-union-list. That is what you should be using to get the union of a list of sets. Using "apply set-of" doesn't do the same thing; it makes a set of sets instead of giving you their union. In the letrec case you are trying to union a list and a set, and need to use set-union-list on the list. The set-union* procedure doesn't work on a list either, unless you apply it, but then you might as well just use set-union-list. The other problem is that you need an else clause in your cond expression to make the type checker work. Otherwise you get the complaint: Error: Body of single-arm if statement has non-void type: (set-union (free-vars (app->rator lile)) (set-union-list (map free-vars (app->rands lile)))) Expected: void Inferred: (set symbol) > Also, while studying for > Monday's test, I realized I don't have the correct code for the app? > condition of free-vars-lcm+if. COuld you send me the solution please? Do > I need a helper procedure or can I use map (I couldn't get map to work)? It's nearly what you wrote (below as a cond clause): ((app? lile) (set-union (free-vars (app->rator lile)) (set-union-list (map free-vars (app->rands lile))))) > I have a feeling that all of these problems have to do with working with > sets and lists of sets, and I'm missing something I believe. Yes, I hope my remarks above fix that. Gary From leavens@cs.uiowa.edu Sun Oct 29 11:47:06 2000 MIME-Version: 1.0 Date: Sun, 29 Oct 2000 11:49:41 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: typed> and > prompt Content-Type: text/plain; charset=us-ascii Zhen-fang Feng, Yes, type in to the > prompt: (type-check-and-eval-loop) and you should get the type checker again. Gary Zhen-fang Feng wrote: > Gary, > > Some code error can cause the prompt "typed>" changed to ">". I'm > wondering if there is any other way to change the prompt from ">" back to > "typed>" without typing and trying scm54 angain. > > Thanks. > > Zhen-fang From leavens@cs.uiowa.edu Sun Oct 29 21:08:52 2000 MIME-Version: 1.0 Date: Sun, 29 Oct 2000 21:11:25 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Kailex Patel Subject: Re: past exams-spr96-ch1-2-Q.8 Content-Type: text/plain; charset=us-ascii Kailex, you wrote: > This is the question of vector-positive? in spr96, q.8. I actually do not > know how to convert a vector to a list or if at all I have to do that for > this question. When I run this code the errors that show up are as below, so > could you please check this and let me know where I'm wrong. You shouldn't try to convert the vector to a list, and that's where you're going wrong and that also explains the type errors. The stopping condition you should use is a comparison between 0 and the current index (your acc) (or if you were counting up instead of down, between the length of the vector and the current index). > Thanks. Oh! and how many points would I get for a question like this out of > 20 if I did it as below? Just curious. Approximately 0 :-). Seriously, not many, because of the problems noted above. > (deftype vector-positive (-> ((vector number)) boolean)) > (define vector-positive > (lambda (von) > (vector-positive-h von (vector-length von)))) > > (deftype vector-positive-h (-> ((vector number) number) boolean)) > (define vector-positive-h > (lambda (von acc) > (if (null? von) > #f > (if ( > (vector-ref von (- acc 1) 0)) > (vector-positive-h von (- acc 1) > #t) > #f)))) > > Error: Operator type and argument types do not match in: (vector-ref von > acc) > Operator type : (-> ((vector t) number) t) > Argument type list: ((list t) t) > Error: Operator type and argument types do not match in: (vector-positive-h > von (- acc 1) #t) > Operator type : (-> ((vector number) number) boolean) > Argument type list: ((list t) number boolean) From leavens@cs.uiowa.edu Sun Oct 29 23:13:00 2000 MIME-Version: 1.0 Date: Sun, 29 Oct 2000 23:15:32 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Sonny Pham Subject: Re: Solution for picture-similar on Sprint 99 test Content-Type: text/plain; charset=us-ascii Sonny, you wrote: > Hi Gary! I'm trying to solve the question in one of your Spring99 test > chapter 2.3 and 3. I wonder if you have the solution for this test so I > compare it to mine. I still not really understand the tail recusion. > Could you please explain it to me again with an example. Thank you Below is my answer for the picture-similar? problem, which uses tail-recursion, although you may have to desugar the and's and or's to see that more clearly. Gary (define picture-similar? (lambda (pic1 pic2) (let ((len1 (vector-length pic1))) (and (= len1 (vector-length pic2)) (all-similar? pic1 pic2 (- len1 1)))))) (define all-similar? ;; TYPE: (-> ((vector number) (vector number) number) boolean) (lambda (pic1 pic2 n) ;; REQUIRES: n is -1 or a legal index into both pic1 and pic2. (or (< n 0) (and (similar? (vector-ref pic1 n) (vector-ref pic2 n)) (all-similar? pic1 pic2 (- n 1)))))) (define similar? ;; TYPE: (-> (number number) boolean) (lambda (n1 n2) (< (abs (- n1 n2)) 5))) From leavens@cs.uiowa.edu Sat Nov 4 07:29:43 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 07:32:25 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Xiaoding Luo 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: Content-Type: text/plain; charset=us-ascii Xiaoding, et al, Xiaoding Luo wrote: > Dr.Leavens, how come I can't find any code in $PUB/lib/ff-ADT.scm. Sorry, the homework was inconsistent about that. The file is in $PUB/homework/ff-ADT.scm, not in the library. I've corrected the homework file, which in one spot gave the correct location, and in another the wrong one. Sorry for the confusion. In any case look in $PUB/homework/ff-ADT.scm. Gary From leavens@cs.uiowa.edu Sat Nov 4 07:43:30 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 07:46:13 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Kailex Patel Subject: Re: 'cond' and problem 8 of HW4 Content-Type: text/plain; charset=us-ascii Kailex, you wrote: > I really don't get how to go about evaluating the cond and the letrec > grammar in question 8 of desugar-cond. I guess my question is how do I use > the cond-clause to bind it with cond test? and the letrec? I'm not sure exactly what the question is, but for using cond-clauses, you will be using the operations found in $PUB/lib/cond-clause.scm. To extract parts of cond clauses, you will be using the operations cond-clause->test and cond-clause->body; these extract, respectively, the first and second expression in each cond clause. You would use make-cond-clause to create one, but I don't think for the homework problem you need to do that. The grammar for a cond-clause is: <(cond-clause T)> ::= ( ) The following is an example:
typed> (load-quietly-from-lib "lambda-cond-letrec-exp.scm")
loading d:/classes/ui54/lib/decl.scm ...
loading d:/classes/ui54/lib/cond-clause ...
# : void
typed> (parse-lambda-cond-letrec-exp
          '(cond
             ((null? ls) '())
             ((equal? x (car ls)) (cons y (cdr ls)))
             (else (cons (car ls) (recurse x (cdr ls))))))
ERROR: parse-lambda-cond-letrec-exp: bad syntax in expression:  (quote ())
typed> (parse-lambda-cond-letrec-exp
          '(cond
             ((null? ls) 'x)
             ((equal? x (car ls)) (cons y (cdr ls)))
             (else (cons (car ls) (recurse x (cdr ls))))))
(cond ((null? ls) (quote x)) ((equal? x (car ls)) (cons y (cdr ls))) (else
(cons (car ls) (recurse x (cdr ls))))) : lambda-cond-letrec-exp
typed> (parse-lambda-cond-letrec-exp
          '(cond
             ((null? ls) the-empty-list)
             ((equal? x (car ls)) (cons y (cdr ls)))
             (else (cons (car ls) (recurse x (cdr ls))))))
(cond ((null? ls) the-empty-list) ((equal? x (car ls)) (cons y (cdr ls)))
(else (cons (car ls) (recurse x (cdr ls))))) : lambda-cond-letrec-exp
typed> (cond->clauses
         (parse-lambda-cond-letrec-exp
          '(cond
             ((null? ls) the-empty-list)
             ((equal? x (car ls)) (cons y (cdr ls)))
             (else (cons (car ls) (recurse x (cdr ls)))))))
(((null? ls) the-empty-list) ((equal? x (car ls)) (cons y (cdr ls)))) : (list
(cond-clause lambda-cond-letrec-exp))
typed> (car
        (cond->clauses
         (parse-lambda-cond-letrec-exp
          '(cond
             ((null? ls) the-empty-list)
             ((equal? x (car ls)) (cons y (cdr ls)))
             (else (cons (car ls) (recurse x (cdr ls))))))))
((null? ls) the-empty-list) : (cond-clause lambda-cond-letrec-exp)
typed> (cond-clause->test
        (car
         (cond->clauses
          (parse-lambda-cond-letrec-exp
           '(cond
              ((null? ls) the-empty-list)
              ((equal? x (car ls)) (cons y (cdr ls)))
              (else (cons (car ls) (recurse x (cdr ls)))))))))
(null? ls) : lambda-cond-letrec-exp
typed> (cond-clause->body
        (car
         (cond->clauses
          (parse-lambda-cond-letrec-exp
           '(cond
              ((null? ls) the-empty-list)
              ((equal? x (car ls)) (cons y (cdr ls)))
              (else (cons (car ls) (recurse x (cdr ls)))))))))
the-empty-list : lambda-cond-letrec-exp
typed> (cond-clause->body
        (cadr
         (cond->clauses
          (parse-lambda-cond-letrec-exp
           '(cond
              ((null? ls) the-empty-list)
              ((equal? x (car ls)) (cons y (cdr ls)))
              (else (cons (car ls) (recurse x (cdr ls)))))))))
(cons y (cdr ls)) : lambda-cond-letrec-exp
typed>
         (cond->clauses
          (parse-lambda-cond-letrec-exp
           '(cond
              ((null? ls) the-empty-list)
              ((equal? x (car ls)) (cons y (cdr ls)))
              (else (cons (car ls) (recurse x (cdr ls)))))))))
(((null? ls) the-empty-list) ((equal? x (car ls)) (cons y (cdr ls)))) : (list
(cond-clause lambda-cond-letrec-exp))
typed>
Hope that helps. I'll be out of touch until this evening, but send me another email if there's more you'd like me to explain, and I'll get to it right away when I return from the conference I'm going to today. Gary From leavens@cs.uiowa.edu Sat Nov 4 20:44:51 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 20:47:37 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Paul Scott CC: leavens@cs.iastate.edu Subject: Re: hwk Content-Type: text/plain; charset=us-ascii Paul, you wrote: > Hi this is Paul Scott, from 22c54. On the longer problems I always have a > problem using emacs. That is when I evaluate the expression and am then > told all my errors, rarely will it let me go back up and change the code I > already entered, then evaluate it again. This kills me with the long > problems, because it takes a while each time to type the whole thing again, > when I just want to change a little bit. Usually what it does when I try to > do this is just act like it evaluated only part of the expression, so that > causes a lot of errors. Could you tell me a way to do it so I don't have to > type the whole thing over each time? Yes, put your test expressions in a file first, and save the file before running Scheme on it. This file can just have test cases in it. (Use the suffix .tst, which emacs will recognize as a Scheme mode file.) ;;; desugar-cond.tst (load "desugar-cond.scm") (desugar-cond ...) ; a test case The simplest thing is to load the file with the test cases in it to do testing. (load "desugar-cond.tst") If that's too much bother, you can use C-x C-e in Scheme mode from the test file to send an expression before the emacs point (where the cursor is) to Scheme. Come to my office on Monday and I can show you how if that's not clear. Gary From leavens@cs.uiowa.edu Sat Nov 4 21:02:17 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 21:05:02 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Xiaoding Luo CC: leavens@cs.iastate.edu Subject: Re: homework 4, problem 20, has-type Content-Type: text/plain; charset=us-ascii Xiaoding, Xiaoding Luo wrote: > Hi, Gary, could you tell me where I can find deftype and code for > has-type? I can't find it in ff-ADT.scm I tried to answer this earlier, but I'm afraid that (#@%$*) @Home lost the email, since I didn't get my copy... Has type isn't a procedure, but a special form that we added to Scheme to aid in type checking. You shouldn't normally have to use it. But you can see the description of it in the type checker's documentation. http://www.cs.uiowa.edu/~leavens/ui54/docs/typedscm.html#SEC21 Gary From leavens@cs.uiowa.edu Sat Nov 4 21:31:57 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 21:34:37 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Mike Scott Bealer CC: leavens@cs.iastate.edu Subject: Re: Help problem 8, homework 4 Content-Type: text/plain; charset=us-ascii Mike you wrote: > Prof Leavens, > Could you take a look at the attached file please? I can't get it to type > check and I can't figure out why. Thanks, I tried to answer this earlier, but I'm afraid that @Home lost my email to you. So I'm recreating it... The first problem in your code is that you have 2 missing parentheses in desugar-let.scm. After fixing these I get the following, which I'll try to explain. typed> (load "desugar-cond.scm") Type checking "desugar-cond.scm" ... desugar-cond : (-> (lambda-cond-letrec-exp) lambda-cond-letrec-exp) c-help : (-> ((list (cond-clause lambda-cond-letrec-exp)) lambda-cond-letrec-exp) lambda-cond-letrec-exp) Error: Operator type and argument types do not match in: (decl->exp (let->decls exp)) Operator type : (-> ((decl t)) t) Argument type list: ((list (decl lambda-cond-letrec-exp))) The above error is pretty much what it says. let->decls returns a list of decls, but decl->exp expects a single decl as an argument. You may want to use map or a helping procedure. (You have the same problem also for letrec.) Error: Attempt to apply non-procedure: ((map decl->var (let->decls exp)) (map desugar-cond (decl->exp (let->decls exp)))) Operator type : (list symbol) The error message above pretty well describes the error also. The result of (map decl->var (let->decls exp)) is a list of symbols, not a procedure. What you have in the whole expression in the error message is a two pieces of data, the first being applied to the second. You need to tie them together with a procedure. You'll need to use make-decl to create a decl. But these are lists, so you might want to use a helper or map. (You have the same problem also for letrec.) Error: Operator type and argument types do not match in: (decl->exp (letrec->decls exp)) Operator type : (-> ((decl t)) t) Argument type list: ((list (decl lambda-cond-letrec-exp))) This is the same error as the one 2 above, but for letrec. Error: Attempt to apply non-procedure: ((map decl->var (letrec->decls exp)) (map desugar-cond (decl->exp (letrec->decls exp)))) Operator type : (list symbol) This is the same error as the one 2 above, but for letrec. Error: Operator type and argument types do not match in: (cond->else-exp) Operator type : (-> (lambda-cond-letrec-exp) lambda-cond-letrec-exp) Argument type list: () This is pretty much what the type checker is saying also. You didn't give an argument to cond->else-exp. Error: Attempt to apply non-procedure: ((cond? exp) (c-help (cond->clauses exp) (cond->else-exp))) Operator type : boolean Error: unknown global name: else The above 2 errors are because of a missing right parenthesis at the end of your cond clause for the let case. There's a similar problem because you also have a missing right parenthesis at the end of your letrec clause. Error: Attempt to apply non-procedure: ((letrec? exp) ...) Operator type : boolean This is also because of the missing parentheses. Try using emacs to indent the file to find this kind of error. Error: Operator type and argument types do not match in: (cond->clauses exp) Operator type : (-> (lambda-cond-letrec-exp) (list (cond-clause lambda-cond-letrec-exp))) Argument type list: ((-> (number) number)) I think this is also caused by the parentheses. You'll also have a problem when you try to finish this, because your app case is in the else clause of your cond. To get the type checker to not think that your cond is being executed for side-effects, you need a separate else clause like: (else (error "should not happen")) which will solve that typing problem. Sorry my original, and more timely, message didn't get to you. Gary From leavens@cs.uiowa.edu Sun Nov 5 09:18:32 2000 MIME-Version: 1.0 Date: Sat, 04 Nov 2000 18:23:11 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Mike Scott Bealer Subject: Re: Help on problem 8, homework 4 Content-Type: text/plain; charset=us-ascii Mike, Oh, one other thing. Don't forget to include in the cond expressions you write an else clause of the form: (else (error "bad input")) Otherwise it won't pass the type checker. You had an else that did the app case. If you do that, the type checker thinks that the expression is one intended to have side effects, and complains... Gary From leavens@cs.uiowa.edu Sun Nov 5 15:34:43 2000 MIME-Version: 1.0 Date: Sun, 05 Nov 2000 15:37:27 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: "M. Allen" Subject: Re: let/let-rec question about free and bound variables Content-Type: text/plain; charset=us-ascii Mark, you wrote: > i've been trying to understand the full details of 'let' and > 'letrec,' and saw that there weren't many notes about the details of what > is clearly defined as a free or bound variable.. there is a lambda > expression that is equal to the representation of a let statement in EOPL > on page 69 that gives a representative model, but still appears ambiguous > to me on the hw on #5 with the 'free-vars' examples.. it appears that > once a decl->var is declared for a decl->exp, that the decl->exp > automatically become free (as a variable?).. ..so i was just asking in > order to clarify the actualy def's of free and bound vars in > let/let-rec's.. Hmm, I don't think the examples are ambiguous, which ones in particular seem that way to you? The definition of free variables in a let and letrec for the a 1-argument lambda calculus with let and letrec is as follows. FREE VARIABLES IN LET AND LETREC "FV(E)" means the free variables in E def: x \in FV(E) if and only if either: 1. E is a varref, y and x == y (i.e., x and y are the same name) 2. E is an application, (E1 E2), and x \in FV(E1) or x \in FV(E2) 3. E is a lambda, (lambda (y) E), and x \in FV(E) and x is different from y, i.e., x \in FV(E) - {y} 4. x \in FV(E) if E is (let ((v1 E1) (v2 E2) ... (vn En)) B) and x \in ((FV(E1) \union ... \union FV(En)) \union (FV(B) - {v1,...,vn})) 5. x \in FV(E) if E is (letrec ((v1 E1) (v2 E2) ... (vn En)) B) and x \in ((FV(E1) \union ... \union FV(En) \union FV(B)) - {v1,...,vn}) equivalently, for let, x \in FV(E) if E is (let ((v1 E1) (v2 E2) ... (vn En)) B) and x \in FV( ((lambda (v1 ... vn) B) E1 ... En) ) BOUND VARIABLES IN LET AND LETREC "BV(E)" means the bound variables in E def: x in BV(E) if and only if either: 1. E is a varref and false 2. E is an application, (E1 E2), and x \in BV(E1) or x \in BV(E2) 3. E is a lambda, (lambda (y) E), and x \in BV(E) (or x is the same as y and y \in FV(E) ) 4. x \in BV(E) if E is (let ((v1 E1) (v2 E2) ... (vn En)) B) and x \in (BV(B) \union BV(E1) \union ... \union BV(En)) \union (FV(B) \intersect {v1,...,vn}) 5. x \in BV(E) if E is (letrec ((v1 E1) (v2 E2) ... (vn En)) B) and x \in ((BV(E1) \union ... \union BV(En) \union BV(B)) \union ((FV(E1) \union ... \union FV(En) \union FV(B)) \intersect {v1,...,vn})) Thus, y occurs bound in (lambda (y) E) if y \in FV(E) and, for let, x \in BV(E) if E is (let ((v1 E1) (v2 E2) ... (vn En)) B) and x \in BV( ((lambda (v1 ... vn) B) E1 ... En) ) Does that help? Gary From leavens@cs.uiowa.edu Sun Nov 5 17:04:47 2000 MIME-Version: 1.0 Date: Sun, 05 Nov 2000 17:07:31 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: litang Subject: Re: hw4, problem 11 b Content-Type: text/plain; charset=us-ascii Li Tang, you wrote: > Hello Gary, > What do you mean in Hw4.11.b -- type advertised? > Thank you. I just mean the type declared. Gary From leavens@cs.uiowa.edu Sun Nov 5 21:45:22 2000 MIME-Version: 1.0 Date: Sun, 05 Nov 2000 21:48:08 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: litang CC: leavens@cs.iastate.edu Subject: Re: Content-Type: text/plain; charset=us-ascii Li Tang, you wrote: > Hello Gary, > Q13 the following part, '** still doesn't change to '*, and '* doesn't change to '+. Why? > (strength-reduce (parse-arith-expr '(- ((7 ** (1 + 1)) * (5 - 3))))) > = (make-unary-minus > (make-op-call > (make-op-call > (make-literal 7) > '** > (make-op-call (make-literal 1) '+ (make-literal 1))) > '* > (make-op-call (make-literal 5) '- (make-literal 3)))) Good question. The reason is that I don't want the code you write to have to be intelligent. While you could statically evaluate the expression (1 + 1) and get 2, and use that in strength reduction, in general this kind of evaluation is impossible. So you are to simply look for the literal 2 and only strength reduce when you see that. However, if you wish, we can give you extra credit for writing the more difficult version which evaluates expressions when it can statically. (This is called "partial evaluation", and is quite useful for optimization.) Gary From leavens@cs.uiowa.edu Sun Nov 5 22:14:22 2000 MIME-Version: 1.0 Date: Sun, 05 Nov 2000 22:17:08 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: Content-Type: text/plain; charset=us-ascii Shawn, you wrote: > I am getting this error and don't know what causes it > > typed> > (load "free-vars.scm")Type checking "free-vars.scm" ... > ERROR: tc:external-type-vars called with incorrect external type syntax, > before: (lambda-if-letrec-exp) > typed> > (quit)Bye. This is from the type checker's parsing of one of your type expressions. It's trying to tell you that there is a syntax error in a type expression. In this case the error message is not helpful, because it's assuming you're making a different mistake than the one you're making. The problem is in: > (deftype lrh-helper (->( (list lambda-if-letrec-exp) (list symbol)(set symbol)(set symbol) > (lambda-if-letrec-exp)) (set symbol))) You have (lambda-if-letrec-exp) here in parentheses, which to the type checker, looks like a call to a type constructor, but with no arguments. Type constructors need at least one argument, however, so this is a syntax error in the type expression. The problem is fixed by taking the parentheses off from around it, changing it to: (deftype lrh-helper (->( (list lambda-if-letrec-exp) (list symbol)(set symbol)(set symbol) lambda-if-letrec-exp) (set symbol))) Gary From leavens@cs.uiowa.edu Mon Nov 6 11:56:19 2000 MIME-Version: 1.0 Date: Mon, 06 Nov 2000 11:56:43 -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, you wrote: > Hi Gary, > I'm stucking in Q18. I don't know how to handle the types. > I attach my code and error message to you. Just use the untyped interpreter for this problem. The type errors you are getting should all be ignored, I think. -- Gary From leavens@cs.iastate.edu Mon Nov 6 15:15:38 2000 Date: Mon, 6 Nov 2000 15:15:30 -0600 (CST) From: "Gary T. Leavens" To: leavens@cs.iastate.edu Subject: feedback responses Some anonymous feedback: > Don't use the overhead projector. > I can't see when your standing in front of it or > writing. I liked it when you used the chalk board > better. I plan to go back to that and to also ask in class, thanks. > Try dropping the lowest homework score. > I don't like your extra credit policy. > It doesn't help those who need the points. I don't plan on dropping homework scores, which already only count for 30% of the grade. The extra credit policy is not intended to help those who need points, but rather as an outlet for those who want to explore more things. > There is too much homework. > There is no way I can ever get it done on time and > no way to get time to get around to extra credit problems > or recommended. > I have too much homework in my other classes. > The homework is drastically lowing my grade because > they are a lot lower(approx 20%) than my test scores. > I work a long time on the homework too. So it isn't > a lack of effort. Please come and see me for help with the homework if it's taking too long. Send email if you get stuck on a problem and I can try to help. And complain to your other professors... :-) Gary From leavens@cs.uiowa.edu Tue Nov 7 11:14:38 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 11:17:24 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: "M. Allen" Subject: Re: ..eval-arith-expr.. problem on HW4 Content-Type: text/plain; charset=us-ascii Mark you wrote: > ..my code for eval-arith-expr is as follows.. > > (load-quietly-from-lib "arith-expr.scm") > > (deftype eval-arith-expr(->(arith-expr) number)) > (define eval-arith-expr > (lambda (exp) > (variant-case exp > (literal (number) number) > (op-call (left-arg op right-arg) > (op > (eval-arith-expr left-arg)(eval-arith-expr right-arg))) > (unary-minus (arg) arg) > (else(error "eval-arith-expr: Invalid exp" exp)) > ))) > > ------------ > ..i believe the difficulty i am having is with my starting expression for > (op ..... ..i was following the variant case structure as i thought it > should be... but i'm not sure why this op isn't displaying the current op > of the current op-call.. and why it doesn't evaluate it... > > ..i would appreciate any clarification of this that you could have to > offer.. Yes, the problem is that op is a symbol, not a procedure. So you can't call it as a procedure. You can use a helping procedure that takes the symbol op and the two arguments, and decides what to do with it. For example, when op is the symbol +, it will use the Scheme + procedure to add them together. Gary From leavens@cs.uiowa.edu Tue Nov 7 15:16:06 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 15:18:51 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: Content-Type: text/plain; charset=us-ascii Shawn, Shawn Garner wrote: > In "strength-reduce" problem shouldn't > > '(4 ** 3) > go to > '(4 * (4 * 4)) > > or are we only doing it if the exponent is 2? > > and > > '(4 * 5) > > should go to > (4 + (4 + (4 + (4 + 4)))) > > or again are we only doing times 2? Yes, we're only doing strength reduction when the exponent is 2. This is somewhat realistic, since there is a tradeoff between time and space (taken up by the generated code). Gary From leavens@cs.uiowa.edu Tue Nov 7 19:32:43 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 19:35:26 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner 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: problem 13 of homework 4 Content-Type: text/plain; charset=us-ascii Hi, Shawn Garner and Li Tang both pointed out to me that problem 13 of HW4 is a bit unclear about what you are to do. I have added a sentence to the description of that problem to clarify that you are only supposed to perform the strength reduction when the right argument of ** or * is literally 2. Gary > Shawn Garner wrote: > > > In "strength-reduce" problem shouldn't > > > > '(4 ** 3) > > go to > > '(4 * (4 * 4)) > > > > or are we only doing it if the exponent is 2? > > > > and > > > > '(4 * 5) > > > > should go to > > (4 + (4 + (4 + (4 + 4)))) > > > > or again are we only doing times 2? > > Yes, we're only doing strength reduction when the exponent is 2. This is > somewhat realistic, since there is a tradeoff between time and space > (taken up by the generated code). > > Gary From leavens@cs.uiowa.edu Tue Nov 7 20:09:26 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 20:12:10 -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, Li Tang wrote: > Hello Gary, > Do we need to do Q20, as I think this part is what you're teaching right now and some > code in your notes and book? I'm not very understand them. Yes, you need to do question 20. It is just an ADT implementation question. Note that it has nothing to do with the procedure to record transformation. All you have to do is implement the given ADT, which just happens to be one that we've been studying. It uses the "ribcage" representation that you talked about. What that is is a colorful way of talking about the data structure used in the representation, which has the type given in the defrep in $PUB/homework/ff-ADT.scm: (defrep (ff V) (list (pair (list symbol) (vector V)))) Look at the examples to see what this means:
(extend-ff* '(x y z) '(1 2 3)
        (extend-ff* '(e f) '(5 6) (create-empty-ff)))
       ==> (((x y z) . #(1 2 3))
               ((e f) . #(5 6)))
You can see that the result of extend-ff* is a list of pairs, and in each pair is a list of symbols together with a vector. You can use list->vector to make the vector. This is all there is to the "ribcage" Gary From leavens@cs.uiowa.edu Tue Nov 7 22:34:37 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 22:37:21 -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, Li Tang wrote: > Hello Gary, > What's "has-type" mean? Such as -- (has-type (list (pair (list symbol) (vector T))) ff) The has-type expression is something that tells the type checker what the type is. I think there's something about it on the Q&A page. See also the documentation for the type checker from the resources web page. But if you feel you need to use it, just don't use the type checker on that problem. > What's ribassoc to do? Ribassoc is a procedure that returns an element from a vector. See exercise 2.2.7 in the book, or look it up in the index. You did it in a homework problem. See also $PUB/homework/hw2.tst/ribassoc.tst. Gary From leavens@cs.uiowa.edu Tue Nov 7 22:38:31 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 22:41:03 -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, Li Tang wrote: > Hello Gary, > Sorry write to you so often. No problem. > This part I really confuse. > I write part of code, and got error message as following: > > (define ff1 (extend-ff* '(d x y) '(6 7 8) (create-empty-ff))) > # > > ff1 > # te *fail*)))) (if (eq? val (quote *fail*)) (apply-ff ff symbol) val))> > > This is not an error. The way Scheme procedures (i.e., closures) print is like that. Try using apply-ff on ff1 and a symbol... Gary From leavens@cs.uiowa.edu Tue Nov 7 22:45:01 2000 MIME-Version: 1.0 Date: Tue, 07 Nov 2000 22:47:44 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Shawn Garner Subject: Re: Content-Type: text/plain; charset=us-ascii Shawn, Shawn Garner wrote: > I don't quite understand what we are suppose to do in problem 18(hw4). > > Am I suppose to put > (define-record interior (symbol left-tree right-tree)) > at the begining of interior-as-vector.scm? No. You're supposed to implement more or less what define-record does. > is the symbol in the > define-record interior suppose to be 'interior if it is an interior? No, it's a label for an interior node given by the user. > I assume we are suppose to be using variant-cases again? Not for this problem. > Additionally should I put at the beginning of the file > (define-record leaf (number)) No. You aren't going to implement leaf records, just interior. You just need to implement the 5 functions listed at the top of $PUB/homework/interior-as-vector.scm so that they act like the functions automatically defined by define-record. Of course, you will do this without using define-record (or variant-case) itself. Similar remarks apply to problem 19. Gary From leavens@cs.uiowa.edu Thu Nov 9 22:44:15 2000 MIME-Version: 1.0 Date: Thu, 09 Nov 2000 22:47:06 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Li Tang Subject: Re: problem 9 of hw4 Content-Type: text/plain; charset=us-ascii Li, Li Tang wrote: > Hi Gary, > I'm doing Hw4.9, actually the procedure should do both desugar-let > and desugar-cond on the grammar. I changed > my desugar-cond to desugar-cond-let, but I could find .tst file, so > I use desugar-let to test file. That's why I got error message. How > can I test my code? Thank you for your reply. Ah, you're doing an extra credit problem! You will need to make up your own tests. Feel free to copy my tests and edit if you like, but you're on your own for testing an extra credit problem. :-) Gary From leavens@cs.uiowa.edu Fri Nov 10 10:14:37 2000 MIME-Version: 1.0 Date: Fri, 10 Nov 2000 10:17:30 -0600 From: "Gary T. Leavens" Reply-To: leavens@cs.uiowa.edu X-Accept-Language: en,de,fr To: Zhen-fang Feng Subject: Re: lecture note on data-abstraction-part2.txt Content-Type: text/plain; charset=us-ascii Zhen-fang, you wrote: > Hi, Gary, > > I don't quite understand the following example. > > (deftype extend-ff* > (-> ((list symbol) (list T) (ff T)) > (ff T))) > (define extend-ff* ; p. 95 > (lambda (sym-list val-list ff) > (let ((val-vector > (list->vector val-list))) > (lambda (symbol) > (let ((val > (ribassoc > symbol sym-list > val-vector '*fail*))) > (if (eq? val '*fail*) > (apply-ff ff symbol) > val)))))) > > The type of the extended-ff* is (ff T). It seems to me that > > (if (eq? val '*fail*) > (apply-ff ff symbol) > val)))))) > > will return either a type of val or a type of apply-ff. This is the procedural representation, in which the type (ff T) is represented by a procedure of type (-> (symbol) T). Note the currying. So in this case, when you call extend-ff*, it returns a procedure that takes a symbol, and, as you say, returns a value of type T. Hence the procedure returned by extend-ff* does indeed have type (-> (symbol) T), as required. Gary