From leavens@larch.cs.iastate.edu Sat Mar 25 09:52:50 2006 Date: Sat, 25 Mar 2006 09:52:50 -0600 (CST) From: Gary T. Leavens To: Nick Retzl Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS 342 Homework 8, problem 2 question Hi Nick, On Fri, 24 Mar 2006, Nick Retzl wrote: > Dr. Leavens, > > I thought I had the code complete for number 2 but I get an error saying: > apply-env: No binding for fact > I'm not 100% what it means since I thought fact was binded. Here's my part of > the code. Thanks in advance for the help. > > (require (lib "ch3-5.scm" "lib342")) > (displayln > (run "let fact = proc(x) > if zero?(x) > then 1 > else *(x, (fact sub1(x))) > in (fact 6)")) The problem is that in the right hand side of the let-binding, fact is not bound, due to the scope rules for let. You have to apply the idea given directly above the exercise as shown in the makemult procedure to get this to work. 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 Sat Mar 25 20:40:41 2006 Date: Sat, 25 Mar 2006 20:40:41 -0600 (CST) From: Gary T. Leavens To: bkshmidt@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: HW8 Problem 5 hi Brian, On Sat, 25 Mar 2006 bkshmidt@cs.iastate.edu wrote: > On problem 5 should the tracing only be outputed when traceproc is used or > should it also output for proc? Only when a traceproc is called, not for when proc's are used, and not for when a traceproc is formed. > The problem I am running into is that to have > the trace output I have to have the writelns in the app-exp. But to do this it > will affect proc also. To keep it seperate, I only see the option of creating > testers for traceproc such as traceprocval->expressed?. Yes, you will have to either create such test procedures or use a cases expression to do it. Note that apply-procval already uses a cases expression. > Or am I just > overthinking the problem? No, you are thinking along the right lines. 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 Mon Mar 27 21:28:57 2006 Date: Mon, 27 Mar 2006 21:28:57 -0600 (CST) From: Gary T. Leavens To: Stephen Morgan Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: cs342: hw8 question 3 Hi Stephen, On Mon, 27 Mar 2006, Stephen Morgan wrote: > I am having a problem understanding how to handle problem 3 in hw8. This is > probably much simpler then I think, but can you offer any advice? I know what > the problem is asking me to do, but I don't understand how to do it. Put code in apply-procval, which is where closures are applied and you have access to the parts of a closure. 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 Mon Mar 27 21:32:35 2006 Date: Mon, 27 Mar 2006 21:32:35 -0600 (CST) From: Gary T. Leavens To: Stephen Morgan Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: hw8 Hi Stephen, On Mon, 27 Mar 2006, Stephen Morgan wrote: > Sorry about emailing you again, but I am really lost on this homework. I don't > understand problem 5 at all. I don't have a clue on how to start this one. As the problem says, to start: (a) modify the syntax for the language in my-3-5.scm; the concrete syntax should be just like the concrete syntax for "proc", except that it uses "traceproc" instead of "proc". You'll also need to (b) add a variant in the define-datatype for expressions, in my-3-5.scm, for traceproc (call it traceproc-exp). Although there are several ways to proceed, I suggest adding another variant to procval, call it traced-closure, for example. Then modify apply-procval to deal with traced-closure objects when they are applied. 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 Mon Mar 27 21:34:23 2006 Date: Mon, 27 Mar 2006 21:34:23 -0600 (CST) From: Gary T. Leavens To: rmatus@cs.iastate.edu Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: Homework #8, problem #5 Hi Rich, On Mon, 27 Mar 2006 rmatus@cs.iastate.edu wrote: > For Problem 5, are we supposed to modify the proc code that's there, or add the > traceproc in addition? The word "modify" is used several times, without using > the word "add"... just want to make sure we are supposed to ADD traceproc, > based on proc, into the interpreter.. I agree that "add" would be a better word. Leave the currect proc stuff alone and add new code to deal with traced procedures. 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 Mon Mar 27 21:41:57 2006 Date: Mon, 27 Mar 2006 21:41:57 -0600 (CST) From: Gary T. Leavens To: Nick Retzl Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS 342 Homework 8, problem 5 question Hi Nick, On Mon, 27 Mar 2006, Nick Retzl wrote: > I am having troubles with traceproc. I'm not sure how to printout the > arguments and for the last example in the "traceproc-sample-output.txt" I'm > confused with how to print all the "Call..." and then print all > the "Return...". Could you offer any suggestions to get me started with this? > Thank you so much. I have attached my code so you can look at what I have. > Thanks. To print, use Scheme's display, write, displayln, or writeln procedures. I think what you're doing is okay, but you might want to use expressed->printable when printing. 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 Mon Mar 27 21:54:40 2006 Date: Mon, 27 Mar 2006 21:54:39 -0600 (CST) From: Gary T. Leavens To: Rich Matus Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: COMS 342: Formatting with eopl:error procedure Hi Rich, and all, I'm sorry if my message caused any confusion. The formatting strings are only available for the procedure eopl:error, and so will only be useful for problem 3 on homework 8, and not for problem 5. For problem 5, you will have to use write, display, writeln, and displayln. For problem 3 and eopl:error, here are some examples: > (eopl:error 'first "a string") . first: a string > (eopl:error 'first "a string with ~s and ~a" "another" "yet another") . first: a string with "another" and yet another > (eopl:error 'first "a string with ~s and ~a~n and then a ~s and ~a" "another" "yet another" 'a-sym '("more" "stuff")) . first: a string with "another" and yet another and then a a-sym and (more stuff) > (eopl:error 'second "another ~s" '("more" "stuff")) . second: another ("more" "stuff") Does that help? On Mon, 27 Mar 2006 rmatus@cs.iastate.edu wrote: > Hi, > > I try exactly what you mention below for the formatting, and all mine does is > print the ~s marks... I do it just like your error statements in the > my-3-5.scm file and it still operates the same way. > > Can you post an example with multiple "variables" for an example? Especially > one where it's in the middle of a string? > > Rich > > Quoting "Gary T. Leavens" : > >> Hi all, >> >> I'm back from my trip, so if you are turning in late homeworks, you >> can also give them to me now (or to the TAs). >> >> A student asked me a question about the format strings, which can be >> used with the eopl:error procedure. There is a brief description of >> eopl:error on page 14 of the textbook. The format strings may contain >> codes, like those in printf for formatting output. To see what these >> look like, you can look in section 11.2.3 of the PLT MzSCheme Language >> Manual, available from the Help in DrScheme. But here are the most >> common/useful ones: >> >> * ~n or ~% prints a newline >> >> * ~a or ~A displays the next argument (using the display procedure) >> >> * ~s or ~S writes the next argument (using the write procedure) >> >> * ~~ prints a tilde (~) >> >> See you in class tomorrow. 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 Tue Mar 28 10:44:16 2006 Date: Tue, 28 Mar 2006 10:44:16 -0600 (CST) From: Gary T. Leavens To: Denise Bacher Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: COMS 342: hw8 prob 5 Hi Denise, On Tue, 28 Mar 2006, Denise Bacher wrote: > Dr. Leavens, > I've read the Q&A about this problem, and I think I have what it supposed to be > done, but I'm still getting odd output. I'm not sure if I'm just calling my > displayln's in the wrong place or? I'm not getting enough "Call..." and too many > "Return..." Do you have any ideas? The "Call" problem is that you are equating the call of a traceproc with the formation of the traced-closure. But that isn't right. You only know it's called when you get to apply-procval. The "Return" problem is because you are issuing the return message before the call actually has been run. Use "let" to save the result and do the output at the right point in time. 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 Tue Mar 28 20:52:18 2006 Date: Tue, 28 Mar 2006 20:52:18 -0600 (CST) From: Gary T. Leavens To: Chris Cornelison Cc: Com S 342 TAs -- Kewei Tu , Ru He Subject: Re: CS342 - Recursive Environment Hi Chris, On Tue, 28 Mar 2006, Chris Cornelison wrote: > While I grasp the general ideas of letrec and the recursive environment, I > definitely don't see the picture clearly. Is there a way I can use Dr. > Scheme to trace through the interpreter's execution for the factorial > example? > > I tried the Debug button followed by a require statement and then (run > "letrec fact ...."), but a got errors. Yes, to do this, making a copy of the interpreter that is not in a module, and then after pressing "Run", use (trace eval-expression apply-procedure apply-env) or whatever other procedure names you want to trace, and then try some sample inputs. You can also put in displayln or writeln statements. 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 ------------------------