From leavens@cs.iastate.edu Fri Jan 30 22:45:01 2004 Date: Fri, 30 Jan 2004 22:42:33 -0600 (CST) From: Gary T. Leavens To: mark vanderflugt Cc: Computer Science 342 Staff Subject: Re: scheme question Hi Mark, On Fri, 30 Jan 2004, mark vanderflugt wrote: > hi, i talked to tongjie about a scheme question i had, but he > was not able to answer it and referred me to you. anyways, i was > looking at sample code i came across the code > > (define my-counter > (let ((count 0)) > (lambda () > (set! count (+ count 1)) > count))) > > and it increments each time (my-counter) is typed into the > command line. i got it from > www.cs.utexas.edu/users/wilson/schintro/schintro_122.html > i was curious as to how it was able to remember the 'private' > count variable each time it was called. thanks for your time, This is because of the equivalence between "let" and the application of a lambda, and because the closure produced for a lambda remembers its environment. As we'll discuss on Tuesday, the above is equal to: (define my-counter ((lambda (count) (lambda () (set! count (+ count 1)) count)) 0)) So when the definition of my-counter is evaluated, the lambda-expression, (lambda (count) (lambda () (set! count (+ count 1)) count)) is evaluated to a closure; let's write this as # where G is the top-level environment (really a pointer to that...). Ok, now we apply this closure to 0, which, according to the semantics, means we make a new environment, call it G', that extends G by binding count to 0. So we might write G' = G + [count |-> 0] Then we evaluate the body of the closure above in G'. That body is itself a lambda-expression: (lambda () (set! count (+ count 1)) count) so it produces another closure, but this one remembers the environment it was created in, which is G': # and this is the value of the expression to the right of the define, and so it gets bound in the global environment to my-counter (which changes G, mutating it, actually, and hence G'). Now if you apply my-counter, as in (my-counter) and if you follow the semantics of Scheme, you'll see that we first find the value of my-counter in the global envionrment, which is this last closure, and then we set up a new environment that extends G' by binding the acutals of the call (none) to the formals (also none). So then we execute the body, (set! count (+ count 1)), in this extension of G', and hence the statement (set! count (+ count 1)) finds count in G', even though it's not in G. We'll discuss all of this at more length in coming classes, but you can also look at chapter 3 of EOPL for details. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------- From leavens@cs.iastate.edu Tue Feb 3 21:50:07 2004 Date: Tue, 3 Feb 2004 21:49:37 -0600 (CST) From: Gary T. Leavens To: tongjie chen Cc: Computer Science 342 Staff Subject: Re: type in ex04? Hi Tongjie, On Tue, 3 Feb 2004, tongjie chen wrote: > one testcase (nat-leq 15 742) ==> #f > should it be #t You're right. I've corrected that. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From leavens@larch.cs.iastate.edu Sun Feb 8 17:02:56 2004 Date: Sun, 8 Feb 2004 17:02:31 -0600 (CST) From: Gary T. Leavens To: Brian Dorn Cc: Dustin John Holmes Subject: Re: Student Comment Hi Brian, Dusty, On Sun, 8 Feb 2004, Brian Dorn wrote: > In the exercise 3's Dusty Holmes had the following comment: > > "Can you make sure the section hyou tell us to read is correct since page > numbers aren't on the online version of the book. Section 1.3.1 does not > have anything about Let in it." > > I'm assuming he's talking about the SICP book. Yes, he's right, it should have been 1.3.2. The page numbers were right. Sorry for the confusion. > I thought you would be interested in his comment. I have not had a chance > to investigate his claim that the online book doesn't have page numbers. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------ From leavens@cs.iastate.edu Mon Feb 9 13:06:23 2004 Date: Mon, 9 Feb 2004 13:05:36 -0600 (CST) From: Gary T. Leavens To: Iris Cc: Computer Science 342 Staff Subject: Re: cs342_exercise6_Question Hi Iris, On Mon, 9 Feb 2004 irisch@iastate.edu wrote: > Question: Why test-ex6 is a Unknown variable? If I set inser-before-all.tst under my home > directly~cs342/ex6 > Thank you very much. > > Regards, > Iris > > ***************************************************************** > (load "inser-before-all.scm") > Type checking "inser-before-all.scm" ... > .. done type checking "inser-before-all.scm" > insert-before-all : (forall (t) (-> (t t (list-of t)) (list-of t))) > loading inser-before-all.scm ... > Name: Tzu-Chun Chang > Section: A, Tongjie Chen, Brian Dorn, Dalei Li > typed> (test-ex6 "inser-before-all") > : line 3: Unknown variable: test-ex6 > Skipping evaluation because of the type errors... The test-homework file only works with homework, not with exercises. If you want to test an exercise, and if we have a .tst file for it then copy the .tst file to your directory, and load it directly. So instead of (test-ex6 "inser-before-all") you would do (load "insert-before-all.tst") We don't currently have such a .tst file, but I'll try to put one up. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------- From leavens@cs.iastate.edu Wed Feb 11 15:41:11 2004 Date: Wed, 11 Feb 2004 15:40:38 -0600 (CST) From: Gary T. Leavens To: Brian Dorn Cc: Michael McCown , cs342s@cs.iastate.edu Subject: RE: Test Solutions Hi Michael, I agree with Brian. You can make up your own checks. But I've also made answers to the two tests you asked about from the exams web page for the course. On Wed, 11 Feb 2004, Brian Dorn wrote: > Michael, > > Answers for the F01 exam were discussed in recitations today. If you have > questions about whether or not your solutions are correct (at least for the > coding ones) I suggest you try to run them in scheme using the test case > examples that are provided on the exam. As far as whether or not we can > post solutions, I will leave that question for Dr Leavens to answer. > > Brian > > -----Original Message----- > From: Michael McCown [mailto:mmccown@iastate.edu] > Sent: Wednesday, February 11, 2004 3:13 PM > To: cs342s@cs.iastate.edu > Subject: Test Solutions > > > This is primarily directed toward Prof. Leavens, but I was wondering if > it was possible to get the solutions to Exam 1 Fall 01 and/or Ch1-2.2 > Spring 99. The reason I ask is because i'm unsure if the studying i'm > doing is productive or not without answers. > > Michael McCown > -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------- From leavens@cs.iastate.edu Thu Feb 12 00:21:53 2004 Date: Thu, 12 Feb 2004 00:21:32 -0600 (CST) From: Gary T. Leavens To: Eric Douglas Nath Cc: cs342s@cs.iastate.edu Subject: Re: some exam questions Hi Eric, On Wed, 11 Feb 2004, Eric Douglas Nath wrote: > Hey do you think one of you guys could quickly explain what "regularity" of a > language is By "regularity" we mean that a language has few or no exceptions to its rules. For example, the syntax in Scheme is very regular in that to invoke a procedure or operator of one uses a (, and then the operator name or procedure, and then the arguments, and then a ). This is more regular than using f(x,y) and x + y. Most languages have regular rules for forming identifiers (i.e., the lexical syntax of identifiers is regular): for example any number of alphabetic and numeric characters following some alphabetic character. However, early dialects of Fortran only allowed seven characters in identifiers. This was irregular in that the user had to remember a special case. Regularity makes things easy to implement, but is not necessarily the best thing for humans, as you can see from normal human languages like English. The regular rule for forming past tenses in English is to add -ed (or -d if there is already an "e" at the end) to the verb form: he trucks, he trucked, I accumulate, I accumulated, etc. But there are lots of irregularities in the most common verbs: I sit, I sat, I eat, I ate, etc. > and what you mean by special forms of data types as described in > class? I'm still a little fuzz on these.... A special form is a piece of built-in language syntax that has some special rule of evaluation. A classic example is the-expression in Scheme, which is a special form for the Boolean datatype. In (if E1 E2 E3) E2 is evaluated only if E1 is not #f, and E3 is evaluated only if E1 is #f. Other special forms attached to the Booleans are Scheme's "and" and "or". However, "not" is not a special form, but a mere procedure. It doesn't have any special rule of evaluation, unlike "and" and "or". Similarly "define" and "lambda" are special forms. Does that help? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------ From leavens@cs.iastate.edu Thu Feb 12 17:33:26 2004 Date: Thu, 12 Feb 2004 17:32:19 -0600 (CST) From: Gary T. Leavens To: Brian Wicks Cc: Computer Science 342 Staff Subject: Re: Chez Scheme Hi Brian, On Thu, 12 Feb 2004, Brian Wicks wrote: > Just wondering...When you install Scheme on your pc and you get the class > library do you just copy everything into the lib directory that scheme uses > or do I make a new one? Thanks It's best to make a new directory for the class library. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------ From leavens@cs.iastate.edu Fri Feb 13 10:12:25 2004 Date: Fri, 13 Feb 2004 10:11:57 -0600 (CST) From: Gary T. Leavens To: Brian E. Wicks Cc: Computer Science 342 Staff Subject: Re: Scheme on Windows Hi Brian, On Fri, 13 Feb 2004, Brian E. Wicks wrote: > I am still having trouble getting scheme to run on windows. It won't load files using > (load "file") > > Is there a certain location for localize.scm? I am really frusterated. You have to adjust the batch files or shell scripts that you use to run scheme appropriately so that it finds localize.scm. The localize.scm file itself is usually placed in the lib directory. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------ From leavens@cs.iastate.edu Mon Feb 16 00:26:00 2004 Date: Mon, 16 Feb 2004 00:25:41 -0600 (CST) From: Gary T. Leavens To: ehennis@iastate.edu Cc: Computer Science 342 Staff Subject: Re: HW2 problem 2 Hi Evan, On Sun, 15 Feb 2004 ehennis@iastate.edu wrote: > I am doing problem 1.2 on page 7 of the text. It says to rewrite the > grammar not using *or+. What are we supposed to make turn > into? The example turns it into (#t (foo.()) 3) More precisely said, 1.2 says to write a grammar for that is equivalent to the one given on page 6, but without that grammar using the * or + notations. Then give a revised derivation for, as you said, (#t (foo.()) 3) (which is the "above" derivation on page 7). Does that help? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------ From leavens@cs.iastate.edu Mon Feb 16 00:34:42 2004 Date: Mon, 16 Feb 2004 00:25:41 -0600 (CST) From: Gary T. Leavens To: ehennis@iastate.edu Cc: Computer Science 342 Staff Subject: Re: HW2 problem 2 Hi Evan, On Sun, 15 Feb 2004 ehennis@iastate.edu wrote: > I am doing problem 1.2 on page 7 of the text. It says to rewrite the > grammar not using *or+. What are we supposed to make turn > into? The example turns it into (#t (foo.()) 3) More precisely said, 1.2 says to write a grammar for that is equivalent to the one given on page 6, but without that grammar using the * or + notations. Then give a revised derivation for, as you said, (#t (foo.()) 3) (which is the "above" derivation on page 7). Does that help? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------ From leavens@cs.iastate.edu Mon Feb 16 00:35:15 2004 Date: Mon, 16 Feb 2004 00:33:52 -0600 (CST) From: Gary T. Leavens To: Carl Limyao Cc: Computer Science 342 Staff Subject: Re: CS342 - Homework 2 Question Hi Carl, On Sun, 15 Feb 2004, Carl Limyao wrote: > Hello Dr. Leavens, > > I was working on the 342 homework due on Tuesday and I had a question > over two of them. Problems 5 and 6 of the homework which are exercises > 1.8 and 1.9 in the Essentials of Programming Languages book don't seem > to ask a question. Rather, do it does ask a question, but is then > answered right away. > > For example: > > 1.8 - In the definition of remove-first, if the inner if's alternative > (cons ...) were replaced by (remove-first s (cdr los)), what function > would the resulting procedure compute? > > remove > > To me that sounds like the right answer, and thats what the book > states. Let me know if I'm going crazy. Since I typically don't give answers before the homework is due, let me be diplomatic. :-) The "remove" following exercise 1.8 is a heading for the next thing discussed, namely the procedure remove. The answer to 1.8 shoud be a sentence saying what function is computed; if it is appropriate to describe that function in terms of the function computed by a procedure discussed in the text you can do that. However, it would be nice to describe the behavior of that function (in a more direct or mathematical way; say what it computes). That is, I think, what the question is asking. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------- From leavens@cs.iastate.edu Tue Feb 17 11:06:15 2004 Date: Tue, 17 Feb 2004 11:03:30 -0600 (CST) From: Gary T. Leavens To: Michael McCown Cc: Computer Science 342 Staff Subject: Re: Canceling Class (not going to happen) Hi Michael, You're right, but I still can't afford to cancel the class; we need to move on... On Tue, 17 Feb 2004, Michael McCown wrote: > According to the email below from Gloria, she suggests that many > companies looking for CompSci majors will only be in attendance today. > > Michael McCown > > Begin forwarded message: > > > From: "Gloria M. Cain" > > Date: February 12, 2004 8:38:25 AM CST > > To: "ugrads (ugrads)" > > Cc: "Gloria M. Cain" > > Subject: ATTN UGRADS: FW: LAS and Business Spring Career Day > > > > This is another reminder of the Career Days next week. The College of > > Engineering Career Fair is Tuesday, Feb. 17 from 1-8 p.m. The College > > of LAS/Business Career Days is Wednesday, Feb. 18 from 1-7 p.m. > > If you are looking for a full-time position OR an internship/co-op, I > > would recommend going to both. > > If you can only go to one, I would recommend going to the Career Day > > on Tuesday. There are quite a few companies looking for Com Sci who > > will only be here on Tuesday.--Gloria > > > > -----Original Message----- > > From: Rosenquist, Nancy L [LAS] [mailto:nrosenqu@iastate.edu] > > Sent: Thursday, February 12, 2004 7:41 AM > > Subject: LAS and Business Spring Career Day > > > > Dear Faculty/Advising Colleagues, > > Wednesday February 18 from 1-7p is the LAS and Business Spring Career > > Day at Hilton Coliseum. Despite a still sputtering economy there are > > 137 organizations participating. Many will be hiring LAS interns and > > May/August graduates. I would appreciate it very much if you would > > send the attached poster to your students and/or discuss the event > > briefly in your class/with your advisees. Should you want more > > information you can go to the Spring Career Day web site, > > http://www.careers.iastate.edu/springcareerday/default.htm. Thanks > > for your assistance. > > > >   > > Steve Kravinsky, Director > > Liberal Arts & Sciences Career Services > > Iowa State University > > 102 Catt Hall > > Ames, Iowa 50011 > > Phone (515)294-4841 > > Fax (515)294-7446 > > srkravi@iastate.edu > > www.las.iastate.edu/students/careerservices > > > -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From dorn@cs.iastate.edu Tue Feb 17 22:40:00 2004 Date: Tue, 17 Feb 2004 21:43:55 -0600 From: Brian Dorn To: cindyhsu@iastate.edu Cc: cs342s@cs.iastate.edu Subject: RE: questions for hw2. To answer your first question, I believe the problem is in how you are calling set-member?. (set-member? (e S)) You should just be passing in the two arguments e and S, rather than trying to apply the procedure e. Thus it should look more like: (set-member? e S) Secondly, if you have: (set-equal? (set-remove 1 (set 2 3 1)) (set 3 2)) ==> #t (set-equal? (set-remove 1 (set 2 3 4 8)) (set 3 2 4 8)) ==> #t Then you can infer that the order of elements in a set does not have an effect on their equivalence. Thus the set (2 3 4 8) is the same as the set (3 2 4 8). Set-remove doesn't really need to care about the order of the set for any particular reason. Brian -----Original Message----- From: cindyhsu@iastate.edu [mailto:cindyhsu@iastate.edu] Sent: Tuesday, February 17, 2004 9:36 PM To: cs342s@cs.iastate.edu Subject: questions for hw2. Hi, For hw2 #7, after I download the implementation form, I start to fill out the first function set-add under its deftype like this: (define set-add (lambda (e S) (cond ((set-empty? S) (cons e '())) ((set-member? (e S)) S) (else (cons e S))))) I try to run it under the typed scheme and it says: typed> (load "set-ops.scm") Type checking "set-ops.scm" ... set-ops.scm: line 79: Operator and argument types don't match Offending call: (set-member? (e s)) Operator type : (forall (t) (-> (t (list-of t)) boolean)) Argument type list: ((forall (t) t)) .. done type checking "set-ops.scm" Skipping evaluation because of the type errors... I have been looking for the error for an hour and still have no clue where is it or there is a bug in a compiler or something, some help please? Also, does the order of the items in the set matters? For example, you said "`set-remove' takes an item out of a set (or returns its set argument unchanged if the element argument was not in the set argument)." But you give the example, (set-equal? (set-remove 1 (set 2 3 1)) (set 3 2)) ==> #t (set-equal? (set-remove 1 (set 2 3 4 8)) (set 3 2 4 8)) ==> #t A bit confused... Thanks, Cindy From leavens@cs.iastate.edu Wed Feb 18 21:45:03 2004 Date: Wed, 18 Feb 2004 21:44:25 -0600 (CST) From: Gary T. Leavens To: Paul Johnson Cc: Computer Science 342 Staff Subject: Re: COMS 342: Running typed scheme on home machine Hi Paul, On Wed, 18 Feb 2004, Paul Johnson wrote: > I apologize if you have already answered this or if it is readily apparent > on the class website. > I am looking for a way to run the typed scheme interpreter on my home > computer and have looked through most if not all of the resources that are > online. I asked the TA in recitation today and he mentioned directions on > the website. Is there such a thing? Or will I have to ftp and telnet through > to the department machines? I am running GNU-emacs and have Chez Scheme > running just fine. The Ta seemed to indicate that I just needed to load the > right file. > Thank you for your patience, Take a look first at the course "Running Scheme" page: http://www.cs.iastate.edu/~cs342/running_scheme.shtml#home to install Scheme and SLIB. Sounds like you did this, but be sure to get SLIB also. Now follow the link there to the course "Scheme Library" page: http://www.cs.iastate.edu/~cs342/library.shtml This will help you install the library which you'll need. Then you need to also install the shell scripts or batch files for running our versions of the interpreters. As you're running cygwin, take the files scheme342*cygwin from $PUB/bin and edit them to suit your install. That should do it. I've updated the course's scheme library page to be explicit about this. Sorry it wasn't as detailed before. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------- From leavens@cs.iastate.edu Wed Feb 18 21:51:41 2004 Date: Wed, 18 Feb 2004 21:51:24 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Debugging problem in Scheme: (set-add 1 2) Hi Jacob, On Wed, 18 Feb 2004, Jacob Lynch wrote: > Did I set up something wrong in my popeye config files? Every time I get an > error running homework scripts such as (set-add 1 2) it kicks me out of > scheme. Is it supposed to do this, because I have to reload the set-ops.scm > and my code each time I get back in. Thanks for any help! If the type checker passes your code as type correct, but your code encounters a runtime error, this can happen. Try using the untyped interpreter if that's the case. However, the typed interpreter shoudl stop you from evauating somethign that would cause such a problem. For me, when I try to run (set-add 1 2) I get: (set-add 1 2) : line 2: Operator and argument types don't match Offending call: (set-add 1 2) Operator type : (forall (t) (-> (t (set-of t)) (set-of t))) Argument type list: (number number) Skipping evaluation because of the type errors... typed> So if you're using the untyped interpreter, try using the typed one to debug. In any case, 2 isn't a set, so you can't legally do (set-add 1 2) and don't need to test that. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------- From leavens@cs.iastate.edu Wed Feb 18 22:10:19 2004 Date: Wed, 18 Feb 2004 22:02:52 -0600 (CST) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: cs342s@cs.iastate.edu Subject: Re: questions for hw2. Hi Cindy, On Wed, 18 Feb 2004 cindyhsu@iastate.edu wrote: > For #13, the swapper, after I tested the first test which the result is: > > typed> (define lst1 (parse-s-list '(a b c d a b c d))) > lst1 : (list-of sym-exp) > typed> (swapper 'k 'a ',lst1) > (unquote lst1) : (list-of symbol) > > I don't understand why is that and I don't see any error in my code: This is because you have used the comma above in ',lst1. typed> ',lst1 (unquote lst1) : (list-of symbol) The comma operator is sugar for unquote, see the Revised Report on Scheme if you want details. But just leave the comma out. > Also for #7 union*, I don't understand how can lambda make space for multiple inputs or > none? The set-union* operator must be programmed with an unrestricted lambda. See the Revised report on Scheme's section on procedures http://www.cs.iastate.edu/~cs342/SCM-html/r5rs_6.html#SEC29 or the code examples page under "Procedures" and "variable arity" procedures: http://www.cs.iastate.edu/~cs342/code-examples.shtml#Procedures We did talk about this in class, and it's also in the lecture notes. > Can I say from Tuesday to Thursday, the amount of homework is a lot? Really... Yes, you can say that. I think if you follow the tips I gave in class, it won't take too long. But if you don't it will... There's always the late policy; if you can't finish it all by Thursday either start it earlier or hand it in later... -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------- From leavens@cs.iastate.edu Wed Feb 18 22:10:39 2004 Date: Wed, 18 Feb 2004 22:09:50 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Students and Staff -- Amin Babaei-Bourojeni , Brian Wicks , Com_S_342 , Computer Science 342 Staff , Chun Yu , Iris , Bobby Myers , Nick Shafer , Varnit Khanna Subject: RE: trustme! Hi Jacob, On Wed, 18 Feb 2004, Jacob Lynch wrote: > Okay, well thanks for your help. I had a problem with set-add, but I used > trustme! in the file I load it from. Is this okay? Thanks! No, you should never use trustme! in your own code; that essentially turns off type checking. Hence the type checker can't help you. I should have mentioned this in class. (I do use trustme! in programming some of the helpers we give you, e.g., the ones in $PUB/lib/sym-exp.scm), to get around limitations of the type checker, primarily for the parse- procedures. But I do it so you won't have to in your code; that is, I'm trying to lift the language up to something that can be type checked in writing the helpers. See http://www.cs.iastate.edu/~cs342/docs/typedscm.html#SEC28 for details on trustme!.) Similarly you should never use has-type-trusted in your code. For problems that can't be type checked without using these, I will tell you not to use the type checker at all in your code. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------- From leavens@cs.iastate.edu Wed Feb 18 22:38:59 2004 Date: Wed, 18 Feb 2004 22:37:09 -0600 (CST) From: Gary T. Leavens To: Dustin J Holmes Cc: Computer Science 342 Staff Subject: Re: Homework 2 #15 Hi Dustin, On Wed, 18 Feb 2004, Dustin J Holmes wrote: > I am having a problem with the typed interpreter on part b of problem 15 > and also on problem 13 > > Below is the code for my recursive portion of my flatten function with the > lines before and after, for your convenience, and then the output of the > typed interpreter...any help would be appreciated. > > ... code omitted... > typed> (load "occurs.scm") > Type checking "occurs.scm" ... > occurs.scm: lines 45 to 46: Clauses of cond expression have different types > lines 45 to 46: Left clause's body: (cons (car los) (flatten-helper > (has-type-trusted (list-of sym-exp) (cdr los)))) > lines 48 to 49: Right clause's body: (cons (flatten-helper > (has-type-trusted (list-of sym-exp) (car los))) (flatten-helper > (has-type-trusted (list-of sym-exp) (cdr los)))) > Left clause's body's type: (list-of sym-exp) > Right clause's body's type: (list-of datum) > ... done type checking "occurs.scm" > Skipping evaluation because of the type errors... > typed> (exit) There are two problems. First, you're using has-type-trusted. Don't do that; I forgot to mention this before, but see my last email to the class... Instead you must use the sym-exp helpers to change the types as necessary. That is, if the car of (los) is a symbol, then use (sym-exp->symbol (car los)) to extract the car with type symbol. If the car is not a symbol, then use (sym-exp->s-list (car los)) to extract the car with type (list-of sym-exp). There are two other problems. First, you can't use cons to put a list and another list together to get a list. Think about examples to solve this problem. Second, if the argument type of flatten is (list-of sym-exp) then when the list los is empty, it still has type (list-of sym-exp) so use '() instead of it if you want the return type to be different. And follow the grammar. Your procedure flatten-helper doesn't and contains undoubtedly repeated code with flatten. You'll lose points for this. Not to mention it will be harder to program. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------- From leavens@cs.iastate.edu Wed Feb 18 23:44:30 2004 Date: Wed, 18 Feb 2004 23:44:03 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: RE: help with s-list and type checking Hi Jacob, On Wed, 18 Feb 2004, Jacob Lynch wrote: > Sorry to bother you so much, but I'm really having a lot of trouble with > this homework. I understand how to do the functions, but I can't get any of > them to type check. I just keep getting so many type errors on the set and > slist stuff. Where would the best place on the webpage be to look for > information on this? Thanks again! I would suggest looking at the code examples page and then looking at examples of the kind you are trying to write. There are several examples of s-list and symbol expression procedures there, with type checking. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------- From leavens@cs.iastate.edu Thu Feb 19 13:48:33 2004 Date: Thu, 19 Feb 2004 13:47:57 -0600 (CST) From: Gary T. Leavens To: Ryan Hanks Cc: Computer Science 342 Staff Subject: Re: Terminal-related question Hi Ryan, On Thu, 19 Feb 2004, Ryan Hanks wrote: > I have trouble back-spacing when I'm in the typed interpreter. My backspace > character shows up as ^H and it doesn't delete any characters. I'm using > the cygwin shell and I ssh to popeye using the ssh client that is > distributed with cygwin. Any suggestions? Easiest fix: run Scheme from inside emacs. If you don't want to do that, see $PUB/docs/erase-message.txt for how to fix it. Let me know if that works. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------- From leavens@cs.iastate.edu Thu Feb 19 13:57:53 2004 Date: Thu, 19 Feb 2004 13:57:24 -0600 (CST) From: Gary T. Leavens To: Luan Chan Cc: cs342s@cs.iastate.edu Subject: Re: make-list doesn't work? Hi Luan, On Thu, 19 Feb 2004, Luan Chan wrote: > I was testing my code last night and everything was working fine > and well. Today when I went to go print out a transcript however, it keeps > giving me the error "Unknown variabled: make-list". I was under the > impression that make-list was under the common scheme libraries. Make-list > does work until I load "type-check-and-eval.scm". Any reasons why this > would cause an error? There is no procedure named "make-list" in the Revised Report on Scheme; that is, it's not standard. Now, it is built-in to Chez Scheme, but it's not in SCM (because it's not standard). Because it's not standard, the type checker doesn't know anything about it. Hence the type checker complains that it doesn't know what it is, as you see. I don't know why you want to use make-list anyway. If you need to use it, write your own version. But I suspect you are doing something wrong if you think you need it. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------