From leavens@cs.iastate.edu Thu Feb 19 17:43:09 2004 Date: Thu, 19 Feb 2004 17:42:53 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: lecture Hi Jacob, On Thu, 19 Feb 2004, Jacob Lynch wrote: > I was wondering, since you said C++ doesn't support proper tail recursion, > will we still see the large performance gain by using it in C++? C++ would > still be adding to the stack each time wouldn't it? Thanks! If you use tail recursion it will ad a stack frame in C++, just as a full recursion would, as most C++ compilers (and most Java compilers etc.) don't do tail recursion elimination. So don't try the tail recursion trick in C++; instead, in those languages use a while loop (or for loop etc.). -- 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 20 12:05:11 2004 Date: Fri, 20 Feb 2004 12:04:59 -0600 (CST) From: Gary T. Leavens To: Cindy Hsu Cc: Computer Science 342 Staff Subject: Re: flatten errors Hi Cindy, On Fri, 20 Feb 2004 cindyhsu@iastate.edu wrote: > I didn't know there is a difference between list of sym-exp and list > of symbols. Yes, there definitely is. For example, (a b c) is both a list of symbols and a list of symbol expressions, but (a () (((b) ())) (c)) is a list of symbol expressions that is not a list of symbols. The type checker also distinguishes the types (list-of symbol) and (list-of sym-exp) because sym-exp and symbol are different types. > If there > is, for flatten-s-list revised version: > > (deftype flatten-s-list (-> (list-of sym-exp) (list-of symbol))) Ok. > is there a function that transfer list of symbol > to list of sym-exp? No, but you have no need of that in writting flatten or flatten-s-list. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------ From leavens@cs.iastate.edu Sun Feb 22 21:52:16 2004 Date: Sun, 22 Feb 2004 21:51:59 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: RE: HW3 Hi Jacob, On Sun, 22 Feb 2004, Jacob Lynch wrote: > Okay, I'll try to rewrite the occurs-twice function. Sorry about problem 4, > I misread that, whoops. Ok. > One last quick question. Question 7 is kind of > ambiguous to me. I'm not sure what you are asking for. Do you want us to > define vector-index all in one procedure so that we put the iterator in the > bottom of the function using letrec (rec so it's recursive inside the let)? Yes, so it's recursive inside the letrec. That is define the helping procedure in a letrec instead of in a separate top-level define. > Thanks for your help! Happy to. -- 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 23 18:49:03 2004 Date: Mon, 23 Feb 2004 17:33:28 -0600 (CST) From: Gary T. Leavens To: Tongjie Chen Cc: Computer Science 342 Staff Subject: Re: how to run scheme342 from inside emacs Hi Tongjie, One problem, I'm hoping the only one, is that the definition of scheme-program-name was not what I use. It was just "scheme342", but should be: ;;; The following uses "scheme342" as the scheme interpreter ;;; (setq scheme-program-name "sh -c scheme342") Try that and see if it helps. I've updated the sample-.emacs files for the course to reflect this. -- 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 24 12:57:50 2004 Date: Tue, 24 Feb 2004 12:29:22 -0600 (CST) From: Gary T. Leavens To: Elisabeth A Seagren Cc: Computer Science 342 Staff Subject: Re: HW3 First part Hi Beth, On Tue, 24 Feb 2004, Elisabeth A Seagren wrote: > I have a question, or questions about problem 4. I understand what we are > supposed to do.. but I am confused as to how the test case actually calls > the function. Here are the tests from the $PUB/homework/hw3/average3-c.tst file: (((average3-c 0) 3) 6) ==> 3 (((average3-c 0) 3) 12) ==> 5 (((average3-c 100) 5) 93) ==> 66 > The test (the first one) calls average3-c on 0, but then the > value that is returned 0, is tried to be applied to 3 (so it looks like (0 > 3) ) and I get an Attempt to apply non-procedure (which makes sense since 0 > is not a procedure). Try giving the inputs (average3-c 0) and ((average3-c 0) 3) to the interepreter; The syntax in average3-c (0) or (average3-c (0 3)) is incorrect. > I was under the understanding (for currying) that the > function average3-c took the same arguments as average3 and instead of > evaluating the function, we convert the numbers to a list and then use > helper functions to evaluate it, such as one that sums the numbers, and one > that divides them by 3. No, you're thinking of variable argument (or unrestricted) lambda. > Am I understanding this at all? If average3-c > does take only one number, then how do you add that to the next > values? By returning a procedure that does that. > Doesn't it need a list of numbers, or a number and list, or all 3 > numbers which is then converted to a list for the helper functions? No, try the inputs above in the typed interpreter to see what's going on. -- 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 24 22:39:10 2004 Date: Tue, 24 Feb 2004 22:38:50 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: RE: HW3 Hi Jacob, On Tue, 24 Feb 2004, Jacob Lynch wrote: > Can you help me with a couple problems in hw3? When defining free-vars, you > gave us three test cases in class, but are there not four? Does quote-exp? > not matter? There are 4 cases in the homework, that's right. The problem is to extend the definition I gave you to deal with quoted expressions. I indicated that you'd have to do this in class. > Also, when defining bound-vars for if expressions, I was thinking that you > would just union the bound-vars of the test, true, and false cases, but this > doesn't seem to be working. Can you perhaps point out something I might've > missed? Thanks again! That sounds like it should be right. Try debugging your expression on some concrete examples. It could be that our set-ops is wrong, or it could be that other cases are wrong. Try to see which it is by doing something very simple with an if. -- 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 25 18:59:18 2004 Date: Wed, 25 Feb 2004 18:56:48 -0600 (CST) From: Gary T. Leavens To: 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: About all those helping procedures for the grammars in 342 Hi all, A student wrote in anonymous feedback... On Wed, 25 Feb 2004, WorldWideWeb wrote: > At this point in the course, I am having great difficulty > understanding the rationale behind our creation of the "var-exp, > quote-exp, lambda+-1+quote-exp, lambda-exp, etc." data types, and > the purposes that they are meant to serve respectively. > > Although you have provided many useful resources on the webpage, I > have not found documents clearly alluding to all of these items > insofar as their purpose, manipulation, and interrelation. > > As understanding of these items is critical to completing the > assigned (generously proportioned) homeworks, I would suggest > providing discussion in some form of the roles of these data types > and their purposes. This is a good question. There are two parts to it. First, why all the different grammars? There are several reasons for that. For learning about functional programming, the key thing to have you understand is the correspondence between a grammar and the structure of the program that works with it; you need to see several examples to internalize that. I'd like you to see every programming problem as having some input grammar that determines the shape of the code (its outline). Also when you work with programming languages, the grammar is often changing, as you change the syntax. Second, what are these helping procedures doing (var-exp, quote-exp, etc.)? At the top level, they are giving us an abstract interface to the language defined by a grammar; we take the abstract data type concept very seriously in this course, hence we need to manipulate data through an abstract interface. Let's see what's happening in more detail, by looking at the ones in lambda-1+quote-exp.scm for example. We have several groups, indicated by the comments in the file where their types are declared. First: (deftype lambda-1+quote-exp? (type-predicate-for lambda-1+quote-exp)) which is a type predicate. This procudure is like boolean? or number? and can be used for dynamic type checking. It's pretty useless for what you are doing. Next comes: (deftype var-exp? (-> (lambda-1+quote-exp) boolean)) (deftype quote-exp? (-> (lambda-1+quote-exp) boolean)) (deftype lambda-exp? (-> (lambda-1+quote-exp) boolean)) (deftype app-exp? (-> (lambda-1+quote-exp) boolean)) These are case testers (discriminators), which can tell if something that is a lambda-1+quote-exp is actually in one of the various subcases. You need to use at least 3 of these in all procedures that work on the lambda-1+quote-exp grammar, since you have to distinguish four cases. For example, (var-exp? l1qe) is true if l1qe satisfies the grammar for in ;;; ::= ;;; "var-exp (id)" ;;; | (quote ) "quote-exp (symbol)" ;;; | ( lambda ( ) ) "lambda-exp (id body)" ;;; | ( ) "app-exp (rator rand)" Notice the comments off to the right of this. These tell you the names of everything. That is var-exp? is named as it is because of the "var-exp" at the right. So quote-exp distinguishes the second production from the rest of the grammar. Next there are the "observers": (deftype var-exp->id (-> (lambda-1+quote-exp) symbol)) (deftype quote-exp->symbol (-> (lambda-1+quote-exp) symbol)) (deftype lambda-exp->id (-> (lambda-1+quote-exp) symbol)) (deftype lambda-exp->body (-> (lambda-1+quote-exp) lambda-1+quote-exp)) (deftype app-exp->rator (-> (lambda-1+quote-exp) lambda-1+quote-exp)) (deftype app-exp->rand (-> (lambda-1+quote-exp) lambda-1+quote-exp)) These are used to extract parts of the productions. These are also named according to the comments in the grammar. For example, we have "var-exp (id)" so the name is var-exp->id. It takes something that's a lambda-1+quote-exp, checks that it's a var-exp, and returns (as a symbol) the inside it. The lambda-exp->id extracts the in the lambda expression, and lambda-exp->body extracts the inside it; these also follow the same naming convention. (The names are like we'll see later in the book.) Next come the "constructors": (deftype var-exp (-> (symbol) lambda-1+quote-exp)) (deftype quote-exp (-> (symbol) lambda-1+quote-exp)) (deftype lambda-exp (-> (symbol lambda-1+quote-exp) lambda-1+quote-exp)) (deftype app-exp (-> (lambda-1+quote-exp lambda-1+quote-exp) lambda-1+quote-exp)) These make data structures of type lambda-1+quote-exp. Essentially they take their inputs and form them into something from which the rest of the procedures can work. Sometimes the outputs of these procedures are called, in the compiler consturction literature, "abstract syntax trees" (or ASTs). These ASTs can also be thought of as variant records: there is some way to tell them apart from each other. Another way to think of them is as follows: Suppose lambda-1+quote-exp is an abstract class in C++ or Java and var-exp, quote-exp, lambda-exp and app-exp are all subclasses of it. Then these are the constructors of those subclasses. Finally there's the parser: (deftype parse-lambda-1+quote-exp (-> (datum) lambda-1+quote-exp)) this converts the input (in this case a Scheme datum) into the ASTs. We can talk more about it in class, and it will be clearer when we get a bit farther in the material... -- 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 26 19:21:39 2004 Date: Thu, 26 Feb 2004 19:20:26 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Free-vars Help Hi Jason, On Thu, 26 Feb 2004, Jason Cook wrote: > Here is what I have for free-vars: > > (deftype free-vars (-> (lambda-1+quote-exp) (set-of symbol))) > (define free-vars > (lambda (expr) > (cond > ((var-exp? expr) (set expr)) There is a type error in the above line. (set expr) is not a (set-of symbol) but is instead a (set-of lambda-1+quote-exp). > ((app-exp? expr) > (set-add (app-exp->rator expr)(free-vars (app-exp->rand expr)))) You're not exactly following the grammar above, as (app-exp->rator expr) is a lambda-1+quote-exp, and so you need to recurse on it, not just add it to the set of free variables of the operands. It's also the same type error as before. > ((quote-exp? expr) the-empty-set) > (else > (free-vars-lam expr))))) I wouldn't separate out free-vars-lam into a separate procedure, although there's nothing exactly wrong with it, it leads to a difference between recursion structure of the grammar and the recursion structure of the program, and also to mistakes like... > (deftype free-vars-lam (-> (lambda-1+quote-exp) (set-of symbol))) > (define free-vars-lam > (lambda (lam-expr) > (if (null? lam-expr) > the-empty-set A lambda-1+quote-exp can never be null, so the test in the if above is wrong. > (set-remove (lambda-exp->id lam-expr) > (free-vars (lambda-exp->body lam-expr)))))) This part seems right. > I believe I am following the grammar and have the first three cases > right (crosses fingers), yes, in those cases the outline is mostly right, and this is better, but still not exactly following the grammar there or getting the types right. > but I am having trouble with the recursive > call to handle if it is a lambda expression. First off, I am not sure > what the base case would be so I don't know if checking for null is > right, in fact I don't think it is, but am not sure what the case > would be. You're correct in your feeling that it's not right. That's why I'd just put the last two lines in free-vars. > Also, I know I need to call set-remove of the lambda id to remove any > of the following instances of that from the set, but can't seem to > figure the types out, or the order out. Can you give me any hints? Yes, the type checker gives type errors when it sees an inconsistency. That means that the line it points out as wrong may not be the line you need to change to fix it. Indeed, the types in the lambda case are right, and it's all the rest that are wrong in your code. > I really wish I could have turned this in on time, but since I was > behind last week and spent all last weekend getting that done, along > with tuesday's assignment, along with a 331 assignment, along with a > java program, all due wednesday, I didn't have time to get started on > the second half of the homework early, and unfortunately I only have 1 > hour on wednesdays where I am not at class/work/driving to class/work > or eating. I understand. But it does seem like you're getting the idea better; this is close to being right. -- 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 costanza@web.de Sun Feb 29 15:15:51 2004 Date: Sun, 29 Feb 2004 18:41:52 +0100 From: Pascal Costanza To: ecoop-info@ecoop.org Subject: [CfP] 1st European Lisp and Scheme Workshop +----------------------------------------------------------------------+ | 1st European Lisp and Scheme Workshop | | June 13 - Oslo, Norway - co-located with ECOOP 2004 | | Supported by ALU (pending) | +----------------------------------------------------------------------+ Important Dates: Submission deadline: April 5, 2004 Notification of acceptance: April 26, 2004 ECOOP early registration deadline: May 7, 2004 For more information visit http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/ or contact costanza@web.de Overview: Lisp has a tradition of providing a fruitful basis for language design experiments for many decades. The structure of Lisp, including its current major dialects Common Lisp and Scheme, makes it easy to extend the language or even to implement entirely new dialects without starting from scratch. The Common Lisp Object System (CLOS) was the first object-oriented programming language to receive an ANSI standard. It is, arguably, the most complete and advanced object system of any language. Despite having somewhat disappeared from the radar of popular computer science, Lisp has just started to gain momentum again. Many current trends are strongly influenced by the metaprogramming notions that are prevalent in Lisp, for example Aspect-Oriented Programming, Domain-Oriented Programming, Model-Driven Architectures, Generative Programming, and so on, that make heavy use of metaprogramming in the background. This one-day workshop will address the near-future role of Lisp-based languages in those and related areas. We want to solicit papers that discuss the opportunities Lisp provides to capture and enhance the possibilities in software engineering. We also want to promote lively discussion between researchers proposing new approaches and practitioners reporting on their experience with the strengths and limitations of current Lisp technologies. Suggested Topics: * Macro-, reflective-, meta- and/or rule-based development approaches * New language features / abstractions * Case studies * Experience reports * Industrial applications * Aspect-Oriented Programming * Domain-Oriented Programming * Generative Programming * Ambient Intelligence * Context-Oriented Programming * Unanticipated Software Evolution * Design Patterns Submission Guidelines: Potential attendants are expected to submit * either a long paper (10 pages) presenting scientific and/or empirical results about Lisp- and Scheme-based uses or new approaches for software engineering purposes * or a short essay (5 pages) defending a position about where research and practice based on Lisp and Scheme should be heading in the near future Submissions should be mailed as PDF to Pascal Costanza (costanza@web.de) before the submission deadline. From leavens@cs.iastate.edu Sun Feb 29 16:07:30 2004 Date: Sun, 29 Feb 2004 16:06:41 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Hw3 Problem 14 Hi Jason, On Sun, 29 Feb 2004, Jason Cook wrote: > I have a question about problem 14. Now that the app-exp rands and > lambda-exp id can be lists, does this mean that it would be a good > idea to have helper functions for these? Yes, you will probably need some helper functions to deal with the lists in this problem. You can try using set-minus instead of set-remove for one thing, but then you'll need a helper to convert a list of symbols (what lambda->ids returns) to a set of symbols. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------- From leavens@cs.iastate.edu Sun Feb 29 17:19:19 2004 Date: Sun, 29 Feb 2004 17:18:59 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Hw3 Problem 14 Hi Jason, On Sun, 29 Feb 2004, Jason Cook wrote: > I think I almost have it, but am stuck on what to do for > (app-exp->rands). I know that it is a list of expressions so it > cannot be empty, The list can be empty (e.g., as in a call like "(set)"). > but how do I pass it so that it is a list, but then > calls free-vars on each element to check for each case? That is > essentially what needs to happen correct? I know that requires a > helper function I guess I'm just not sure if I'm thinking about it > correctly. Yes, you can write a helping procedure to recurse over the list, or use map. > Is the deftype for free-vars-rands correct? yes. > And if so, > how does it stop? Since the list of lambda+if-exp won't ever be null > will it, because that is not in the grammar? Right, there is no null in the grammar. The base cases in the grammar are the cases that don't involve recursion. For lambda+if-exp, these are var-exp and quote-exp. If you write out a grammar for lists, you'll see that null is the base case for lists for the same reason. -- 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 Thu Mar 4 22:37:48 2004 Date: Thu, 4 Mar 2004 22:35:28 -0600 (CST) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: Com S 342 TAs -- Dalei Li , Brian Dorn , Tongjie Chen Subject: Re: Hw3. Hi Cindy, On Thu, 4 Mar 2004 cindyhsu@iastate.edu wrote: > You didn't say we can't use parse-lexical-addr-exp for hw#19 so I > assume we could use it? No, you can't use that either. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------- From leavens@cs.iastate.edu Sat Mar 6 16:16:53 2004 Date: Sat, 6 Mar 2004 16:16:04 -0600 (CST) From: Gary T. Leavens To: Jonathan Bentz Cc: Computer Science 342 Staff Subject: Re: question about lexical depth homework problem Hi Jonathan, On Sat, 6 Mar 2004, Jonathan Bentz wrote: > Regarding the problem due on Tuesday about lexical depth, can we use the > free-vars procedure for lambda+if-exp that we wrote for an earlier part > of hw3? The reason I ask is because that free-vars procedure also used > our set-ops.scm procedure and I didn't know if you wanted us to use sets > for this homework. Yes, you are welcome to use earlier procedulres that you wrote, I think some of these will be helpful, especially the free-vars procedure. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From leavens@cs.iastate.edu Sat Mar 6 16:26:48 2004 Date: Sat, 6 Mar 2004 16:26:30 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Problem 19 Hi Jason, On Sat, 6 Mar 2004, Jason Cook wrote: > I don't know how to start problem 19. The hints say that lexical- > address calls lexical-address-helper immediately and passes it a > lamba+if-exp and a list of lists of symbols. I can't figure out what > this list of lists of symbols would contain, and why it would need to > be put in this format. Did you look at the examples at the bottom of the hints file? > The hints also mention adding any other helping procedures below > lexical-address-of-var-exp. Does this mean that there will need to be > a helper for every case in the grammar, such as lexical-address-of- > quote-exp, lexical-address-of-lambda+if-exp, etc. etc? No it doesn't mean that. In general that's a bad idea as it obscures the structure of the program. But you may need some other helpers to do odd tasks, like converting sets to lists or things like 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 Sat Mar 6 22:14:39 2004 Date: Sat, 6 Mar 2004 16:16:04 -0600 (CST) From: Gary T. Leavens To: Jonathan Bentz Cc: Computer Science 342 Staff Subject: Re: question about lexical depth homework problem Hi Jonathan, On Sat, 6 Mar 2004, Jonathan Bentz wrote: > Regarding the problem due on Tuesday about lexical depth, can we use the > free-vars procedure for lambda+if-exp that we wrote for an earlier part > of hw3? The reason I ask is because that free-vars procedure also used > our set-ops.scm procedure and I didn't know if you wanted us to use sets > for this homework. Yes, you are welcome to use earlier procedulres that you wrote, I think some of these will be helpful, especially the free-vars procedure. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------- From leavens@cs.iastate.edu Sat Mar 6 22:22:56 2004 Date: Sat, 6 Mar 2004 22:22:15 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: Problem 19 Hi Jason, On Sat, 6 Mar 2004, Jason Cook wrote: > I did look at the hints and examples down there. Part of the > problem is that I don't really follow those either. I don't see > why there would be 3 lists of those symbols passed to lexical- > address-helper in the first place. There are not three lists of symbols passed to this helping procedure, there is a single list containing three elements, each of which is a list of symbols. Each of the sublists corresponds to a the variables declared in a region. Look at the examples for how lambda is handled. The last sublist always contains the free variables found in the expression. The next-to-last sublist, if any, always contains the list of variables declared in the outermost lambda. > I also don't understand the > first example: > > (lexical-address-helper (parse-lambda+if-exp 'x) > '((p q r x y) (w z x) (car ls)) ) > ==> (x : 0 3) > > Why does it return (x : 0 3)? I understand that the depth of x in > this case is zero. But why would the position be 3? If it is > treating it like an index I guess I understand, but even if that is > the case, what about the second occurrence of an x, the one in (w z > x)? Does that just get overlooked since it found the first x? Yes, it is treating the numbering as an indexing scheme, and in the 0th sublist, (p q r x y), the index of x is 3. Since x occurs in this 0th sublist, the second one is ignored. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------- From leavens@cs.iastate.edu Sat Mar 6 23:07:43 2004 Date: Sat, 6 Mar 2004 23:04:05 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: HW3 #19 Hi Jacob, On Sat, 6 Mar 2004, Jacob Lynch wrote: > I'm working on number 19 here, and I'm pretty close to getting it. I just > have a few questions. What is a quote-exp? Is it just (quote a) or > 'a? Yes. You can look at the parsing procedure to see that. > I > don't understand what we want to do with that exactly. I sce I didn't put any examples in the homework statement about this. I will add some... I guess I was assuming you'd figure this out from the previous problems, in which we also had quote expressions. Essentially, you can transform quote expressions in a straightforward way to the output. As discussed in class, a quote expression does not contain any variable uses or definitions, it's just a way of constructing a symbol. > Also, it says that > we must check to make sure our free variables have distinct lexical > addresses; does this mean that some of our tests may fail, if the globally > bound (free) variables are given different arbitrary values than the ones > your test cases check for? No, it means that we do not check for these in our testing, you have to check them by hand, yourself. That is primarily to make sure our tests do not have the problem you imagined. > One more thing, when I was copying Example 2 and Example 3 from > lexical-address.scm I noticed that you were missing a parenthesis from each > example. I believe it is a closing parenthesis that goes before the second > argument to lexical-address-helper. Thanks, I'll fix that. > I'm really glad you gave us this helping file with examples and tips > otherwise this would've taken me at least twice as long, but it's not so bad > now that I understand it (mostly). Good. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------- From leavens@cs.iastate.edu Sat Mar 6 23:08:01 2004 Date: Sat, 6 Mar 2004 23:07:06 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: HW3 #19 pt. 2 Hi Jacob, On Sat, 6 Mar 2004, Jacob Lynch wrote: > Actually, I just got the "lexical-address" test for hw3 to pass for test > cases. But, I know that my implementation isn't quite correct, because it > doesn't give distinct values for all free variables. Yes, the problem statement does say you are supposed to check this yourself. Our tests do not check for this. > Actually, I reread your hints, and it sounds like we should make a list of > free vars using free-vars, and then use the position of each variable in > there to give a distinct value. But to do this, it seems like we would have > to generate that set at the beginning (so we have the whole expression to > work with) and then pass it around to all the helping functions to check to > see if it is a free var before we return the address (only the lexical > address function would need it, but it can't get it unless we pass it to a > couple other function first). So, is this how you would recommend > doing it? That might be reasonable, he said, being coy. > We'll have to modify your starting functions to allow for a set of > variables, and I didn't know if we could change them or not. Thanks! You can change the helping procedures as you see fit. However, I would add that there is no way to determine a position from a set, as sets are unordered. It does seem easier to determine a position from a list, as list are ordered. :-) -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------- From leavens@cs.iastate.edu Sun Mar 7 08:39:36 2004 Date: Sun, 7 Mar 2004 08:39:11 -0600 (CST) From: Gary T. Leavens To: Jacob Lynch Cc: Computer Science 342 Staff Subject: Re: HW3 #20! Hi Jacob, On Sun, 7 Mar 2004, Jacob Lynch wrote: > Thanks, professor, with your help I was able to complete #19 just fine. I > was looking in the book at the definition of #20, and it seems a bit tricky. That's why it's extra credit... > I assume that we won't be taking lexical addresses like (null? free) instead > of (null? 0 0) (for example). You would take as input the output of lexical-address, something like ((null? : 0 0) (free : 0 1)) for example. > But it also says to return #f if the > expression doesn't exist. Is it possible to have multiple data type returns > with the type checker? I'm afraid I've either forgotten or don't know how. You can do that the type checker. So either don't use the type checker or change the problem to make it work (use error instead of returning #f, for example). -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------- From leavens@cs.iastate.edu Sun Mar 7 13:22:03 2004 Date: Sun, 7 Mar 2004 13:21:44 -0600 (CST) From: Gary T. Leavens To: cindyhsu@iastate.edu Cc: Computer Science 342 Staff Subject: Re: Hw3, problem 19 Hi Cindy, On Sun, 7 Mar 2004 cindyhsu@iastate.edu wrote: > > On Sun, 7 Mar 2004 cindyhsu@iastate.edu wrote: > > > I was building the #19 buttom up, for the lexical-address function which is > the highest > > > one, I tried to copy its input arugument to a (list-of (list-of symbol)) > version without > > > the "if", "lambda"...etc so I can pass it to the helper function. While I was > doing the > > > conversion and copying process, I have to create extra 3 helper functions and > yet it just > > > gets more and more complicated. I am wondering did I do it right? > > > > It doesn't sound like it. The "if" and "lambda" are not symbols, but > > are reserved words. They would not be in the list of lists in the > > second argument to lexical-address-helper. > > Yeah, that is what I meant. Say if I have > (lexical-address (parse-lambda+if-exp '(if t (car ls) ls))) > I want to make '(if t (car ls) ls) into '(t (car ls) ls) so I can do > (lexical-address-helper (parse-lambda+if-exp '(if t (car ls) ls)) '(t (car ls) ls)) > That is what I meant by making a copy without the "if" and "lambda". It's very complicated > > to do. No, you have this wrong. The result of parsing is not a list at all, but an abstract syntax tree. Your idea wouldn't work if the expression was more deeply nested either. Instead, you should get a list of all the free variables in the parsed expression, as the hints say, you should use your free-vars procedure to produce such a list. Then the initial call for your example would be equal to: (lexical-address-helper (parse-lambda+if-exp '(if t (car ls) ls)) '((t car ls))) > > > Was I suppose to pass a > > > copy of (list-of (list-of symbol)) version to the helper? If it's true, > turning lambda+if- > > > exp to (list-of (list-of symbol)) seems very HARD to achieve. > > > > No, I think you misunderstand this. > > Can I please have some hints for (lexical-address exp don't-know-what-to-pass-lolos)? > Did you look at the revised file of hints $PUB/homework/hw3/lexical-address.scm, especially at the bottom? -- 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 Mar 8 07:25:52 2004 Date: Mon, 8 Mar 2004 07:22:28 -0600 (CST) From: Gary T. Leavens To: Jason Cook Cc: Computer Science 342 Staff Subject: Re: lexical-address-helper Hi Jason, On Sun, 7 Mar 2004, Jason Cook wrote: > Well, I got this part working, I hope. It works for the test cases > at the end of that file but I guess if it gets a different or > specific var-table format where it doesn't need to check the whole > thing, then it might not be right. Anyway. > > Can you explain how this works? > > (lexical-address-helper (parse-lambda+if-exp '(quote x)) > '((a b) (p q r) (x y) (car ls)) ) > ==> (quote x) > > (quote x) is not a lexical address is it? Since lexical-address- > helper only returns lexical addresses, how is this right? If > (quote x) is somehow a lexical address, how do you use any of the > lexical address helpers to get it in that format? (quote x) is a lexical address expression. Look at the problem statement for the grammar for lexical-addr-exp, and look at the type declaration for lexical-address-helper: (deftype lexical-address-helper (-> (lambda+if-exp (list-of (list-of symbol))) lexical-addr-exp)) > The same goes for this example: > > Example 3: > (lexical-address-helper (parse-lambda+if-exp > '(if (p u) (h x) (t y))) > '((x y) (q r p) (h t u)) ) > ==> (if ((p : 1 2) (u : 2 2)) > ((h : 2 0) (x : 0 0)) > ((t : 2 1) (y : 0 1))) > > I don't understand how that is a lexical address. It is not of the > form ( symbol : number number). Can you please explain this, > otherwise I do not understand how to build the result. you'll have to use the helping procedures in "lexical-addr-exp.scm"to build the result. -- 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 Mar 8 07:26:01 2004 Date: Mon, 8 Mar 2004 07:25:36 -0600 (CST) From: Gary T. Leavens To: Nick Shafer Cc: cs342s@cs.iastate.edu Subject: Re: Free vars Hi Nick, On Sun, 7 Mar 2004, Nick Shafer wrote: > Are we being required to write the free vars + lambda if procedures over > to use lists or is it being provided for us? It seems like a huge task > to rewrite this, espeacially since i was going on the assumption that > this was due on the 19th and now have two days to complete it. Certainly not; you can use the free-vars procedure you wrote earlier which returns a set, and then you just have to convert the set into the type you need (a list). Such type conversions are typical in (functional) programming. There was only one place where the mistake about the due date was, and I had announced it fairly clearly in class and it's in the homework file and the syllabus correctly. -- 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 Mar 8 18:19:46 2004 Date: Mon, 8 Mar 2004 18:19:17 -0600 (CST) From: Gary T. Leavens To: Eric Douglas Nath Cc: cs342s@cs.iastate.edu Subject: Re: Hw3, number 19 Hi Eric, On Mon, 8 Mar 2004, Eric Douglas Nath wrote: > Question: What do we do about this lexical-address hw assignment if we didn't > get the free-vars prodedures to work correctly? You said something about > sending the solutions out right before the test, but you didn't include the code > for that last hw in the zip file. Was this intended? Yes, it was as I promised, to allow people to continue working on them. > I'm also a little confused on where exactly to start righting the helper > function for tuesday's homework. And how do we print out/return the lexical > address in the form described in class? If you're willing to take a 0 for those, I can send you solutions to those problems. -- 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 -------------------------------------