SOFTWARE ENGINEERING III
OCTOBER 12,  2015

	INSTRUCTOR:  Hello, hello, echo, close my window here, get less distracting sound from the parking lot.
	Has today been a tough or tired Monday, or just me.
	I feel off my game -- all day, as witness that I picked up water bottle I barely filled, only a fifth of the way -- oh, well -- yeah, I can wait a moment -- I can refill my water bottle.  No, I'll go on less water, be horse and still subject you to my voice.
	We're a little light on people here, wait a minute or so, I'll pull up my racket, I put the homework out.  And we'll see if we can finish that by next week, you can e-mail me if you have questions.  There's a few questions on grammar and on the program, if you want to send me an e-mail, with -- I'm starting on problem number 3 -- am I going on the right track, I'll try to set aside during office hours to apply to such e-mails right away.
	So, during regular office hours, that are posted.  Do you want to setup additional time?  Is that the question?  I didn't put special times just for distance learning, and I can be on breeze monitoring that -- monitoring this room.
	Yeah.  My usual office hours are what?  I need to think myself -- it's -- gosh, I'm not sure -- Monday, Wednesday, Friday, 10 -- if you work, these hour are not good, yeah.
	Thursday hours in the early afternoon -- I think -- something like that -- would you like to setup -- I can setup an hour on the weekend.  Babysitting schedule is always like -- I might be on duty on a particular time, but early afternoon are good.  Should we try to pencil Saturday afternoon from 2-3?  If I were to be sitting on the computer at that time, would anybody else show up?  Okay.
	The other office hours you can try to.  Send me e-mail, if during regular office hour during the week and you don't get me, I should remember to start recording -- if I'm not in the room during regular office hour, dash me an e-mail, if I'm not with a student, I'll remember to check in.  We'll try Saturday at two o'clock?  What did I say?  2 o'clock?  One o'clock?  October 12th that's crazy.
	So Saturday from 2-3 -- let me put that in my calendar now.
	We'll start recording so you can see me put it on my calendar.
	I'm sharing my screen -- if I don't do it now, I'll forget.  Saturday at two p.m.
	2-3 looks like its open.
	ITEC online, one hour.  That will be in the same breeze room we're in right now.
	Okay.
	And -- bring back adobe connect -- we have one or 2 more people, maybe one more person.  Saturday 2-3 or regular office hours that I have listed there.  I'll mention here in the chat, so -- again, send me n e-mail, something might come up, I might not be able to be there, but I'll try.  I have the camera so it's not obscured.
	PROFESSOR:  Let's figure out, where did we leave off last?  Let me say about the homework, -- there's a few grammar problems, and some racket representation problems, so -- yeah, I think it should be not too bad -- getting the grammar stuff again will put you through the test if you're watching without integrating it, it will be tougher, you can send me e-mail -- hey, asking if you're on the right track.
	Hopefully everything you ask, is in my notes.
	I want to say one for one, when I setup homework questions or assign and look at them.  It's often, hey this question here is exactly the same as this example in the notes, just slightly different grammar, but doing the same thing.
	Okay.
	 Pull up doctor racket.
	Last time we had written my-max, if you post that map, which map?  Oh, the one two one map -- yeah, rules here, rules here, I copied the right land side of the rule here and copy the right-hand side of that rule there.  That kind of thing.  Yeah.  It will be easy once you sort of, that's what correspondence is, okay.  So -- yeah, we wrote my-max last time, we wrote functions processing a list of numbers.  And at this point I'm going to stop harping on the template for a list of numbers and -- or the data definition for list of numbers and template for list of numbers an using function for that template.  Assume you know and follow the steps from the design recipe, there's link at top of page, it has fairly work out example involves lists as well.
	We will continue using design recipe for other types and relying on those skills built up over the last few weeks.
	I'm going to stop repeating them in great detail that I have been.
	My-max, we had a problem with my-max, what was it?  We wrote it, it actually worked just fine, what was the issue that we had with running my-max though?  And why was it there?  
	No memory of what went wrong with my-max?  Yeah -- yeah, so, I don't have time to recap, we had exponential growth, we tried running a list on 5 long, it was great, and 18 it was okay, and the longer list it took 30 seconds to come back with an answer.  So somewhere between that, list of length 18 and the list of length 23, we're hitting the exponential growth that made us notice it.  Like well, you find maximum element on list up to 20 objects.
	In real list longer than 20, list of 20 students in class, list of thousand students in major, 10,000 students in Radford, we need to be able to process those.  And we had a problem that we were making recursive call twice.
	Following template for my-max, I have it here commented out, starting online 289 from this file from last time -- we took what we had from the template, recursive call on the rest and first and combined them, if first one was bigger that was the answer, otherwise the answer was, result of that recursive call on the rest of the list.  If the biggest number was not the first once, it was the biggest number of the rest of the list.
	And the problem was, if, that recursive call took one second, maybe that list had 20 items it took one second and call with list of 21 items this recursive call takes one second and this recursive call one second and list for 21 took twice that.  How would you it work if I had list of 22, this would take 2 seconds, this would take 2 seconds if doing them both, would end up taking 4 seconds.
	How long for list of 23, 24, each doubling each time, it doesn't take long to become noticeable.  What I think is interesting, 18 times we didn't notice it at all, so that's kind of cool.
	Okay, what was our solution to this problem?  Was our solution, how to re-fix the problem, we end up taking twice.
	Yeah, instead of making that recursive call twice, make it once and remember, I'll probably say identifiers, because we'll not vary anything, once we set a variable it will have that value and it will never change.
	We'll go ahead and assign to identifier and use identifier multiple times and that's what we did and had new language construct, it was let's star.
	And -- the code we had, go ahead and let star says, give me a bunch of new bindings, hey here is identifier max of rest and give me, let it be, initialize to this value here, my-max rest of a-lon.  And this let-star was a function, not quite a function, but looks like a function.
	This whole, let-star, gray highlighted region is going to evaluate to an answer, what is the answer to a let-star, the idea is get the binding, declare bindings, one here, make new binding more max of rest, and now the answer of let-star is answer to this expression, the body of the let-star.
	And, my answer is the body of let-star, when evaluating, if you see max-of-rest use whatever value you stored a moment ago.
	Okay.
	So that's let-star, and it looks weird with curly and square bracket and I think I mentioned last time.  Square brackets, I can make a bunch of different bindings -- so if I want to introduce X as being 3 times 4, great, I'd go ahead and say, I'll use, turns out use curly or square brackets or round parentheses, racket will let you use any of them in any significance as long as they match up and pair.  I'll use square brackets to emphasize, I'm pairing together 2 things.
	We use in con when we had a question answer pair.  Pair each question with answer.  Here pair each identifier with the expression I'm going to use to initialize it.  Okay.
	So, yeah max-of-rest was identifier and initialized to whatever it evaluated to.
	It was name I introduced is one, X bind to 3 times 4, the curly brackets, I can make them look; however, I want, but I'll use curly brackets to remind myself I have a whole bunch of bindings I could be introducing.
	Curly mean a whole bunch, the round parentheses for calling a function, some expression returning a value from it.
	Okay.
	So, in this example I didn't use, ohm used one expression, I might even full that -- curly bracket into a single line.  But, it will look like this.  And that will be my let-star, let-star followed by list of bindings followed by body of expression.
	I think we even sat down and gave the syntax rules for a let-star, and I think given grammar rules for that, so I won't repeat that.  I want to practice this let-star though.
	And again the general phase is open paren let-star and a bunch of bindings and then the body expression.  And bunch of bindings was a bunch of ID and expression pairs all in their own can curly brackets.  Okay, here is my task for you.
	Let's go ahead and write the quadratic formula.
	So quadratic formula, yeah, high school, I'm all over high school, college is tough but high school was easy, so quadratic formula, if I give you 3 coefficients, A, B, C, and Google it up, what some, what was the quadratic formula?  Let me try it, let me make a new window here -- and I'm going to maybe function called root, where I give it the 3 coefficients, and come back with the result of quadratic formula, involving A, B, C, what was that formula?  How did it work?  What's the, to get the answer did I multiply 2 things?  Divide 2 things?  Add 2 things?  Take a square root?  What was the very last overall step in getting the answer to quadratic formula?  
	So, that's little different, so quadratic formula, that Pythagorean theorem, Pythagorean theorem.  -- if AX squared plus BX plus C equals 0, what is X?  -- so, and you go through and learn techniques in junior high, completing the square and learn the quadratic formula, what they didn't tell you, quadratic formula is just completing the square symbolically.
	So, what does quadratic formula, if you Google it, do I get my final answer by multiplying?  Dividing?  Adding?  Square rooting?  What's the overall step you do in computing the quadratic formula?  Division -- division, yeah, some big fraction, something over something else.
	I'll write this already, -- going to start writing this already.  I'll do something like X equals negative B, plus, plus or minus I'll choose the plus option, square root of B squared minus 4 AC, that whole thing divided by 2 A.
	Look at this from racket perspective if I build top down, I'm dividing 2 things.
	I know how to divide 2 things in racket, open paren slash, first thing and second thing, no problem.
	Which is easier, first thing I'm dividing?  Or second thing I'm dividing, that looks hairy, 2 A, go ahead, -- do this.  Go fill it out now but this might be good to try on your own, sometime goods idea to take that formula and convert to racket.
	What's top part?  This thing here?  This looks like negative B plus some square root, that's the sum of 2 different things, plus of 2 things, plus of something and something.
	Second thing is some big square root, leave that aside for now.
	First part is negative B, go ahead and put in negative B.  Is that right?  Negative B?  Let's see, try it.  What is -- if I say dash 5 and 2 -- I get 3 -- and if I say, by the way, dash 5 and 2 and 1.  What is that answer going to be?  Enter and find out, I guess I can ask the computer -- it's 2, 5 minus 2 minus one.
	And, so, if I put a whole bunch of numbers it keeps subtracting these off, takes first one and subtract these off, if I say dash 5?  I get back negative 5, that's seems a little inconsistent.  To me it's not starting with 5 and subtracting off everything else which are none, that's what I thought after the first 2 examples . does anybody have a special word or term why there's 2 different minus's going on?  What do we call this in Java?  Order operations, AHHH, remember in Java the plus, cross had 2 meanings, it could be addition o or string (Inaudible), in Java the plus is overloaded.  In you have number on both side it's means subtract.  In you have number, no number in front but number after it, it means unary, N negation, that's what's going on here in racket, this is minus doing subtraction, mine -- or dash doing subtraction, dash doing subtraction, dash doing unary (Inaudible). 
It streets differently if it gets one versus more than one.
	Okay.
	Ignore the -- I can't have functions return 2 values, so I'll go ahead and choose one of the 2 answers to give.  By the way that's a lie -- racket, in racket you can have function that's return 2 values.
	Now that we know list, rather than return number, you are return a list with 2 numbers in it.  I can do that with Java and whatever language, in racket you can return 2 answers in a function -- we're not --lost the sound --
	DIANA: Just lost sound -- 
	INSTRUCTOR:  I'm not teaching you racket.
	So -- let's.
	Cond you said already.  Let-star, there's 2 types of define, maybe taught you 5 keywords and that's all the racket   we'll learn.
	-- okay.  Da-da-da Dada where were we?  Negative B -- get negative B by calling the dash, function on B, not subtraction unary negation -- I know how to say square root of something, when writing own code I do this.  I put in.... closed paren so make sure I don't forget closed parens, I can also indent as I'm going, if indent is off I can fix immediately before I get confused.  Square root of what?  Something minus something.  Minus of something and something.
	Oh, B squared minus something, how do I say B squared?  Star of BB if I want.
	How do I say 4 times A times C?  Yeah, the little star, function again.  Function named little star, I'll say, asterisk is identifier and bound to multiplication function.
	Okay.
	So I think we're good, go ahead and try.
	-- root of one, 2, one -- should give negative one back.
	X squared plus 2 X plus one.
	Plug in negative one, you get an answer back.
	Anything else in my head that I can do?  Probably not.  I can sort of work through the math in my head a bit.  Some numbers an I'll make them nice round numbers.  2, 4, 3 -- and all over 2 A, all over 4, let me do this in my head.
	B squared minus 4, if working bottom up, B squared minus 4 -- B squared is 16, 4 times A times C is -- 24, so 16 minus 24 is negative 8.  That's negative I don't like that.  I'm going to make this 5 instead.
	-- 2, 5, 3, B square sd 25, 4 times A times C, 24, one, square root of one is one, negative B plus one, negative 5 plus one.
	It's negative 4 all over 6 -- so -- hopefully I'll get all of that.
	Okay, yeah, go ahead and run this.
	One of 2 tests failed.  I didn't do it right in my head.  Negative one defers from negative 0.666 expected value, that's interesting, here.
	This one here, X squared plus one plus -- so I goofed up formula somewhere I suspect.
	Why is this not working.
	In fact, this is one thing I wanted to demonstrate.  So -- here is getting pretty involved.  Let's see what I want to do and very first -- the thing is second test case did passion which makes me suspicious.
	One times X squared, one, plus 2 times X, negative one, plus one.
	HMMM, let's go ahead and if in doctor racket, I'll go ahead and paste this window, if you haven't been typing along -- there we are, I'll let you sort out all of the parens there.
	So negative 3, should be negative 3 halves -- I think, I got negative 4, 6.  Anyway, let's, first test case that failed.  Run this.  Let's use the stepper.
	Press that step button and that brings up a different window -- and, make it's big.  And so now is this working on the screen, do you see relatively big window that has a green section and purple section?  Okay.  Good.  And the idea is sort of 2 halves.  What was on the left is the original program and go step-by-step and seeing what racket does at every single moment and see what it does on the right.  The part in green is going to expand to the part in purple.
	And so this is the first thing this kind of interesting to notice, the part in green turns into the part in purple.  What's the rule for doing this when I call the function root?  What is the answer?  Part in purple?  It is the body root.  The body of the function.  Everything that was not the head of the function, except everywhere A occurred is replaced by one and where B occurred replaced by 2, and so on.
	So -- so this is actually interesting already so evaluate a function what's the general rule racket uses?  The body of the function, except replace all of the -- now I'll use words, replace each parameter with the actual argument.
	The parameters are A, B, C, those are parameters of function and arguments are 1, 2, 1, respectively, so I'm going step-by-step, the very first step it makes, copy and paste the body of the function, except replace A with one, B with 2, C with 1.  And so we get this -- answer here.
	And now we can go ahead and step again.  What's going to happen not appear, but of to halves it will go, CHA-CHING, what isn't purple now will slide to the other side and what that purpose evaluates to will slide in the beginning, you don't see the sliding it just happens.
	On the left now, is what we had been.  First thing it does, evaluate unary minus, it gives negative 2.
	We keep going ahead and doing this step, step, step, -- and we see it simplifying bit by bit, the green it's doing now, to the part on the purpose.
	Trying to evaluate, can't do division yet, have to figure out different parts.
	And can't figure out first part because of plus in couple things and square root, and can't fee you're square root, because of minus step.  So minus 4, 4, that's ready to go, that gives 0 and start working through square root of 0 and now do plus.  it was sitting there pending.
	Negative 2, divide negative 2 by 2.  And we get negative one, and now check expect of negative one, one, and should be fine, so -- I error message maybe -- oh, I see -- the answer came out as one not as negative -- negative 2 thirds.
	It was passing.
	Worked through arithmetic, I did get 25 minus 24 inside square root, which is one.
	Oh, I took negative 5 plus one, I got negative 6, when I should have got negative 4.
	That's what it was.
	Okay.
	My bad, my check expect was wrong, it should have been negative one, -- that's fine, this was awesome example of using stepper.
	I want you to get you used to, this is what racket is doing every time, when you give expression, hit run, and takes expression, and going to evaluate it, if I can't evaluate, well it does that inner expression and finds inner most expression, evaluates that and comes out and rule, to evaluate the function, take the body of the function and replace parameters with the arguments.
	And we had those terms arguments and parameters with the slides, the lecture that had slides, -- and yeah.  What is, go back and fix this test case here -- negative one kind of boring.
	Da-da-da -- what are, in my function root, A, B, C, are those parameters or arguments?  Parameters.
	Parameters are variables an they're a type of local variable that get as initial -- initialized when you call the function.
	That's another way to think about it.  Parameters are the local variable that's get initializes by how you call a function and arguments, those are the values that you use for initializing the parameters.  2, 5, 3, for example.
	Okay.
	Let's go ahead and write this using let, or let-star.
	In fact we'll come back and see what is let-star and why do they call it star there.  -- okay.  I'm going to go ahead and copy and paste this.
	I'll call it root 2, so we have our own function here, get check expect for that one.
	Expect the same answer.
	Are there any names, this whole big expression, one long expression.  Can you give a name to a sub part of this whole big formula?  Different names going on?  -- 
	Give me something that you want to name a sub part of our answer.  Any name, give me actual name you want to try.  X, yeah, that's sort of what we're calculating, calculating a solution for X in that (Inaudible) formula.  If I say what is X, yeah.  So, I'm thinking more like hey, you're, your teen-age son is in junior high, high school, learning quadratic formula, and you want to point, he's, eyes are glossing over, you want to say, look at little part of it, and what might be a name you use for that sub part of the overall problem?  This whole thing is a big fraction, right?  
	Discriminant, yeah, that's something that remembers algebra, even more than discriminant, do we have names for different parts of fraction?  The numerator.  That might be a good thing, I have this whole thing, and numerator was pretty involved.  It would be nice to figure out numerator and put something here.  And if I wanted to, I can go auto head and name the denominator, I don't have to, but, in this case, we can figure out the expression for denominator, that was 2 A, right?  And say what's the overall answer.  It's going to be the numerator, divided by the denominator, so I'm close need to get that.... filled in, and second version that uses let.  Some people don't want to name denominator.
	The numerator had a big chunk, square root and bunch of stuff in the square root.  Sean is reminding us, high school algebra, they said we have a trick, if there's 2 solutions, or one solution to, is duplicated or occurs twice, the same solution twice, are they going to be complex numbers, is our answer, look at discriminant.  You say what's that?  The thing inside the square root.
	And here is a different bonus, bonus software engineering tip.  Whatever you're doing, if you write a program whatever domain, like chemistry stimulation, econ, something inside a video game, whatever, and there's a term that people in that area use in chemistry or econ or inside video game word world, try to use that as variable names or function names an appropriate.  Use those same terms.
	If mathematician is talking about discriminant, that's sub chunk of whole thing, they have wisdom to give it a name and follow their wisdom.  That was B squared minus 4 AC.
	And now what was the numerator?  It was -- negative B, plus discriminant -- and denominator was that, and overall answer, numerator divided by denominator, another example of let-star, this is 3 names here, and all useful.  Discriminant, numerator and denominator, once done that, overall answer is straightforward.
	First let's see if it all makes sense.
	I'll press run -- let-star, this function is not defined in beginner student.  And -- I'm not ready to let you go to intermediate where let-star is defined because I want you to get more practice with lists before you do that.  We might be good for intermediate student, if nothing else, if you look on homework's page, I have a little file you can download called student extras.
	That lets you stay in beginner student but gives you let-star.
	Okay.
	Save the file -- why do I have to save the file to get this to run, it will look in same directory I'm in, and before I save it -- okay.
	4 tests passed.
	Yeah this version that I did with let-star, works, also works, also passes its test.
	-- by the way, if I, have 2 versions of function, one of which might be reference, other might be try to be faster or do differently for whatever reason and I really want to test them, how can I go ahead and test root 2 to make sure I really didn't goof anything up.  Assuming I'm confident of root one, or the first version.
	And general, whenever trying to solve complicated function in program, you write dumb implementation that's close and then use fancy data structures an try to do things in weird order and runs faster, you can use the same test cases, that helps.
	Can we do more to test it, how about this -- I'm going to generate one hundred thousand random test cases.
	Choose numbers at random, feed into both, root and root 2 and make sure they get back the same answer.
	That's the cool thing when you have reference limitation and fancier implementation, make sure they agree by making up case 100,000s.
	You can find bug that's way.  You would never, not run across by doing regular things.
	Okay.
	Where were we?  -- root 2 here.  Yeah, so I went ahead and did this, was it necessary to name the denominator?  Not really, if I left that branch out and deleted and said divide numerator by 2 A, that still I think is pretty readable.
	So, if you want to name the denominator great, if not, that's fine, too.
	Which do you like better, the version that uses let?  Or the version we had originally up online 3, 4, 5?  Anybody have a preference?  No real right or wrong here.
	So mark is using -- voting for let-star -- one's a little longer and one gets to name the sub parts.  By the way if I did go ahead and did, I could have named denominator, I could have named even more, right?  
	I could have named B squared.  And then here I could have said, B squared, okay.  Something like that.  And that's probably a little too much.  I probably don't need to do this and I could have, NEGB is here and I could use NEGB, and now it's getting worse, harder, I don't like this as much as the top one, there's too many names going on and to many to keep track of.  The top didn't have any names but had to think of it all at once.
	You'll find a happy medium as you, become a programmer.
	Your idea will change, do you need more names?  Does it help to have more names.
	It's, help to, name sub part of problem but a lot of names you have to remember, so trade off.
	I probably did it partly to give more practice with let-star.  To see example where we use 3 of them.
	I'm going to go ahead and rename let-star to let, turns out they're both in the language, and I'll call it let, and like what's the difference between let and let-star.  They have the same syntax.  So this is a valid let statement.  All the right parts, let is the same way, identifier and expression, expression pairs, followed by a body of expression -- however, when I run this, using let, it says, hey variable discriminant is not defined.  For fun, let's say at top level, define discriminant to be 999.  I can now run it.  And it runs -- and it get   the wrong answers.  Why?  Because when it comes around to defining numerator it uses value discriminant, using 999.  Let-star, doesn't get confused by this.  -- I run let-star it runs fine.
	First of all let-star, what's going on.  Which we say discriminant which variable are we talking about?  The one online 19, not the line 17.
	By the way -- define -- 2 to be 2.
	If I press the check syntax button shows where each identifier is bound.  2 is from this lib 18, global variable, like you find pi or -- (Inaudible) discriminant let-star, when you see discriminant, where is that declared.  Where is binding occurrence?  Up here.
	And if I change let-star to let and say -- check syntax to give this nice tool, I mouse over discriminant.  It means this top level one.  Now I'm red ready to define what let means, not let-star, just let.
	It means, give me a bunch of identifier and expressions, bunch of pairs of those, let figures out all the expressions on right-hand side.
	Then go back and bind each to the different, the different identifiers.  So in particular, when it was evaluating this expression it had not yet bound anything to the name discriminant online 21.  So line discriminant in there was the line up on 17.  Let-star works differently.
	It says, I say go ahead and do that first definition and this name discriminant shall be used not only down in the body of let expression, let-star, but it will be used in all the following rules of the let-star.
	Okay?  
	And what's the term that tells you, when talking about variable, where it can be used in program and when you have 2 different variables with the same name, how do you figure out which is being talked about?  There's a particular word that you may have heard.  Not this, certain keyword that helps resolve that in Java sometimes -- but yeah -- scope.  In let, the scope of the new identifiers is the let's body expression.
	In let-star, the scope of the new identifiers is, well as before, -- all following right-hand sides, and the let's body expression.
	Indent that.
	So that's difference between let and let-star, what are the scope of variable that's you use.  And that's/, the thing so -- where does this discriminant get used for let-star?  Not only down here, I can use down here, but also in any of these right-hand sides.
	For let, yeah, so, it seems we're, turns outlet star is the one you almost always want in practice.  yes, not really in there.  Look at this, if I say the body is -- everything there, then I have a slight issue, what is, DUMMY is 2 times denominator.
	Okay?  And so now, this is sort of a forward reference, in let and let-star, let me say discriminant -- copy that name -- copy paste.
	Turns out   the value of discriminant, do check syntax, can even make it let-star.  This works and picks up global discriminant, with let-star, the scope is not all the curly braces but following part of curly braced.  Do check syntax, and discriminant is still the global one.
	This discriminant.  The scope doesn't go above it only goes below.  That's different in Java, in Java when you have a function if you call a local variable online 2, you can't use it before you initialize it, but the scope of the variable I think is the entire function.  Let's try that out -- I'm not sure.
	Try some Java here, I'll make a void method called blah, and going to say, I have an int, X, and, int Y, and, Y plus 2, I know there's going to be error, or is it going to be I don't know what you're talking about when you say Y, or hey, Y has not been initialized yet.  And that's the question in scope.  It cannot find of variable Y.  It doesn't know what you're talking about.  Okay?  So, I guess actually difference in Java the scope of Y is from -- here all the way to the end of the method of the curly bracket.
	So Java is similar to let-star.  The scope does not extend above only from where you are below, even if curly bracket as extend up above.
	By the way, Sean was, when you think the body is, you think the scope would be include entire curly brackets, body again refers to the body expression down here for the let statement.
	Like the body of a function and body of a let.  Yeah.  I knew what I meant.  Okay.
	So, anyway, there's subtle things in scope, we have let and let-star.
	And practice let-star is what we want almost all of the time.  They are technically different.  I'll finish with one little, comment out these check expects here -- and go down here, and go ahead and -- we're using the let-star, sure and take out dummy -- okay.
	And let's use the stepper one more time.
	Step function.  And going to notice something interesting that's going to happen now.  Da-da-da -- so check expect of route 2, 1, 2, 1, take body of root 2, replace A's with -- hey, wait a minute, what's going on.  We had let-star and there isn't any let-star.
	Oh, my goodness, this is interesting.  Let-star turned into what?  A bunch of nested lets.
	Let-star is equivalent to nested lets.  In fact, internally it is syntactic sugar for just that.
	So you have a let where you, in this case, let discriminant be something and then go and have a the body, the body will be another let statement.
	So evaluate that other let statement, except where you see discriminant, use whatever we calculated for that.
	Side note.  Syntactic, sugar, a language feature which internally expands -- gets rewritten as, as other existing features, other existing syntaxes.
	So somebody wrote let and did work to get let to work.
	The person who wrote let-star, was lazy, they didn't really do anything fancy and figure out a lot of stuff.  They said I'll write a little bit of stuff, and when I see a let-star rewrite as I bunch of list and give back to the code that handles let statement.
	Java does things like this all of the time.
	Like plus gets and plus plus, that's good example.  They get rewritten, you have to be a little bit careful with some of those.  But yeah, so -- yeah, I'll leave at that, great example, other examples are auto (Inaudible) you write 4 and turns into new integer of 4, needs capital integer object and only gave primitive INT, but plus plus is better example.
	Go back to that stepper.
	The let-star really racket treats internally as bunch the nested lets, each let was single definition and body, and that body was a nest the let.
	We can hit, step, step, step, and now this is interesting.
	How does let really work?  I say calculate right-hand side and bind them and do -- here is another way -- effecting that same thing -- let the discriminant be blah-blah-blah, it rewrote that as a top level define.  Define discriminant 0 to be some sort of expression and got rid of the let.  Entirely and kept with the body of the let.
	In fact let's step a few more times.
	First of all now it goes ahead, and before we get to this, it's figuring out define, define discriminant 0 to be 0.  Anybody back to the let statement, green part became purple.  That turns in single let, but additional (Inaudible) it's lifting these defines to the top level and go a little more.  By the time we get down to it, we're doing, hey, check expect of numerator one divided by denominator underscore 2, which both top level names.
	So, -- that's how, let works.  It lifts definition to top level and then goes, it has to do rename to go be clever.  When you lift to top level, what if discriminant (Inaudible) if the discriminant is defined as 99 you can't redefine to be discriminant later.  We're not changing any values.
	That's why it had to do a renaming, if I go back, I go back a few steps, when it did that renaming of discriminant 0, there we are.  It went ahead and found all the words discriminant in the scope.
	And turned them -- which is the body of let and turned them into discriminant underscore 0.  Not only did it lift, look at green part on the left -- not only did it take this discriminant and lift it to the top level define, when we try to use it, inside the body, anywhere inside the body of the let, it renamed it as discriminant underscore to 0, the name it used when it lifted it, when lifted it used names not in use anywhere.  Made sure it was Brad new name could not conflict.
	So that's sort of interesting.  Not too worried or concerned about this.  Interesting how let works internally, the fact let-star expands to nest of lets.
	And then this idea of scope, we have 22 forms of scope.
	Go back before we take a break, finish with one last question.  What happens if I go ahead and say -- blah takes in an  int X and very first line is  INT X get   X plus 2.  Clearly this X is new X.
	But question is what is the scope of that new X in particular.  Does this X refer to parameter X or refer to the brand new X in the middle of defining and initializing.
	Okay?  And it turns out in Java, compile it, variable X -- so, in Java doesn't let you redefine the variables, I thought I could -- let me try inside a block -- doesn't like it even inside its own little block, interesting.
	In, so you can't redefine your variable X, in C you can.  C this would make a new internal X, those different, than the one around it.  And, this question about  INT X, X plus 2, which X are we talking about?  That changed in GCC 2.7 to GCC 2.8.  Changed what the scope of the variable was.
	And -- you know, wait a minute how can they change what the language means.
	The reason was, if you read about variables and it was all in English pros description, not a very good description, it was ambiguous what the scope of a variable really was.  In that particular situation.  Most the time it's clear, but not in that situation.  Somewhere in the mid 90s, maybe we're misreading the speck and maybe it should be the other way.  I find that shocking.
	One thing about let and let-star, they're exceedingly clear about what the scope of those variables is.  Unless you do it slightly different.  The language gives you both, turns out let-star is the one you usually want but let language gives you both.
	This, field are not variables -- that's common misconception in Java, because Java makes fields look like variables.
	Fields are members of instruct and their getters for them, if you don't write the getter it fills out for you, field is totally different than a class field or a parameter or local variable.
	Those 3 are all similar to each other and variables with a scope.  But, fields are fairly dramatically different.  So -- that's one thing we won't talk about in this class, if you look at racket, and we do use assignment statement, they have 2 forms for assign, one to assign to field and one to identifier.  Those are different enough in racket, they give different names.
	In Java you use 2 parallel equal bar signs.
	Used for assigning to field and local variable.  And makes you think they're similar.  So -- in this case, since X is not a field, no fields going on, I can't use the word -- this -- at all.  Okay, let's take a 5 minute break.  Be back at 18:55.
	[Break Time] 
	[Break Time].
	INSTRUCTOR:  As soon as I have them will be the answer.
	I'll get a couple graded by Wednesday, although I didn't get to start today after all.
	I need to give out midterm grades to athletes by Wednesday, so I'll be, all day tomorrow is grading.
	So, hopefully, I should have a couple done by then, yes.
	Yeah, it's -- kind of fun.
	I do grade, and I think maybe grade recent ones, more of idea what you need for designer speed.
	I found I need to grade from the beginning, otherwise it drives me batty, like wait a minute.  If I grade homework 3 and then go back and grade homework two, I say why didn't they do this and this, oh, they didn't know that in homework 2, if I graded homework 3, I lose that fact and --okay, record, record.
	PROFESSOR:  The 12th already.
	Okay.
	So that was let-star, first of all using why do we use local variables?  And we have 2 reasons, one I can give names to overall computations an second go ahead and, avoid repeated computation.  The latter being essentially not for programmers to make sense of my program, but have program that's can run effectively.
	And maybe when using Java, why use in variables?  Because, you just do.  First week of Java and do it all the way through, and now we have a more refined answer to that question.  And if you look how to design programs back and talk by mutation then you get a more refined answer.  Start thinking about why do I change variables that change overtime.  This example here, I used with let-star, and the discriminant numerator and denominator, in Java, you probably would use helper variables in those different amounts.
	And that's all good.
	What a lot of people do, they use the same name for all 3 of those things in let-star.  Let B squared minus 4 AC, now that -- Z be, I never took a square root from there.
	-- actually test cases past and hasn't taken a square root.  Did they really pass before?  Let's go ahead.
	Yeah, both, yeah they both passed.
	Should have been square root.
	Anyway.  Where was I.  Write this in Java, this is while sign I do not have good enough test cased.
	The fact they both returns negative one, can you think of a stupid code that would pass all of my test cases, define negative (Inaudible) it would pass all my test cases.
	Don't, take time to do some different test cases and so on.
	In Java write this and a lot of people might use the same variable, let Z be, negative B plus square root of Z, let Z be Z divided by 2 A then return Z at the end.
	That would kind of work and I come along and say what's the value of Z and they're like, well, where?  This on this line, in line, this line it changes.  That's more complicated thing.  And here is another thing.  If you ever reassigned variable I bet you don't have a good name for that variable.  Why?  If it was good name for what held online one, if holds different online 2, you probably, no longer a good name for that, so, if not inside a loop, yeah you shouldn't be reassigned to variables.
	Use a different variable name if you have to.  That's fine.  And then you come up with good names for what it represents.
	Seeing them like this can change how I think of Java programming perhaps.
	I want it get back for a little bit now, we seen let-star, let-star will be a tool you can use, especially when we get to intermediate.  After we turn in this next homework we'll bump up to the intermediate.
	I want to give a knew data definition, a natnum -- natnum.
	Natural numbers, 0 or positive.
	-- then the question is what do you mean by...., sets the pattern.
	Writing for computer, computers can't sense patterns, you have to spell it out.  Just one, 2, 3 and so on, that's what natural numbers are, if you ask mathematician what natural number is, they'll have solid foundational answer for you.  They'll say either 0, OR, and I'm not sure Shane if this was ha you were getting at.  Or what?  My math book they wrote this.  Let S be a success or function.
	Or you can say positive integer, and then we have to define positive and integer.
	So emergency book, ORS of X where K is a natnum.  That's how they wrote in math book, they said this is a definition.  We're going to phrase the same thing, except, by the way, that even give examples of data, here is natural number, here is natural number and again this is math book for math majors in college, not high school.
	And here is another example.  Where S is sum successor function, we're not going to care what S is, there's 0 and S of 0 and think of these as strings.
	-- okay.
	And so on -- well, when they say and so on they mean this, that's what they mean, these are all examples of the data, S, S of S of 0, that will come up a fair amount.  Let's give that a shorter name.  we'll call that 3, when you see there, it's syntax I can sugar of S of S of S of 0.  And natural numbers they define default integers, from fractions -- you know -- from fractions go to ream numbers -- from real numbers to complex numbers.
	And big tower that rests on this definition here.
	We're going to do eventually, how do we do data definitions, we're not going to call it S, if we did we write it like this in racket.  Rather than say K where K is go ahead and do that.  We'll not call function S, what do we call function that's successor function, if you give number, it makes number one bigger, we call it add one.
	And yeah, for us, these are -- add, yeah these -- and so on.
	Okay.
	And so, data definition and examples of data and I can say add one, as long as I fill this with any natnum I'm fine, I decided the line above me is natnum.  Yeah, and you're right giver these shorter names.
	We don't quite think of this as sin tack I can sure in computing in most systems, -- if you want to pretend you're a math major, you can.  So -- okay.  Great, this is data definition, go ahead and -- write a function that process   data of this type.
	The example I gave, other class here, I'll work on this.  Yeah, it's more verbose.  One thing that makes you realize Arabic numerals, they're nice succinct representation, algorithm of map, it gets this exponential factor.  Only, 6 digits you correspond to million calls on your successor function.
	So define.  Let's make -- function called LOL times.
	And going to take in N, give signature for it, take in natnum and return a string.  And, just following the steps of our design recipe, I give data definition, examples of data, start to write a function, check expect LOL star of 3 and it's going to be the string LOLLOLLOL, I use this function when checking Facebook and my friends say something funny, LOL star of 7.
	-- yeah, okay, whatever.
	What other check expect should I have?  Yeah, go ahead and, LOL star of 0.  What should LOL star of 0 be?  -- should be a string that starts and has LOL 0 times and then closed quote.  Fair if you have enough.
	And I think LOL star of one -- I'll go ahead and put down 2, for just (Inaudible) purposes.
	I'll be happy with 0, 1, 7, 0, 1, 3, okay.
	-- the -- go ahead and write the function -- I did not write a template for this data, can you give me the template?  Template for any function handling a natnum.
	Go ahead and call this, N, somebody tell me how I'm going to start the template for this data type?  
	Yeah, exactly, hopefully you're all thinking, shouting in your head silently saying, a cond with how many branches?  This is union type or compound type?  It's union type, so cond with 2 branches.  So, hopefully, that's no surprise.
	Okay.
	What do I need, some question that asks, do I have one of these things or one of those things.
	I shouldn't say int, that should be natnum.
	How do I figure out if I have a 0.  I could say -- that's fine, I could certainly ask that.  It turns out this happens, question happens a lot.  There's also a function called 0.  You might have   guessed that from other function names.
	Either one I'm happy with phrase either way, I like to spell out zero, it feels better in the situation.
	What the question if I have natnum that was formed by adding to another natnum.  I think positive.  Yeah, that's what I'll use here, turns out positive was not built for this.  But, yeah, that captures these 2 branches, I could have said else, which would have been fine, too.  If I have zero net numb, is there any more information I have, no that's it.  If I have natnum created by add one -- or another natnum, I'm going to say --this is the first of the rest of the list, we don't have an instruct with fields inside it that made the bigger object but we have a smaller number inside the bigger natnum and retrieve that smaller number by subtracting one.  You of add one as being constructor, and sub one add being the (Inaudible) nothing deep there, just sort of how it fit   with other things covering.
	Okay.
	By the way, what is the type of sub one of N, what is the type of gray thing that I've -- highlighted.
	Yes,  natnum, how do we know that?  All right.  The thing you're given is add one of natnum and sub one undoes add one, in the same sense, first and rest exactly undo conds.  And, make book is exactly undone by book title, book numb imagines and book copyrighted.  Undo constructor, they're inverses.
	What sort of functions am I going to call on this natnum?  Can you think of any functions I want to call, wait a minute I have a function that's built for natnums.
	So, yeah, according to design recipe and those steps that was new step, relatively recent step, 3 C add the natural recursion.  In the same place there's a self reference in data definition, we have self reference in template.  Okay.  Let's go ahead and write LOL star.  I'll give you all, minute and a half to write LOL star.
	Given we have template, I'll go ahead and put this here.  Add one more.  Put that in here and spacing gets (inaudible).  Put the spacing back.
	Give you 90 seconds to write LOL star.
	And then reflect, how much do you have to add on that's not in the template.
	I'll go ahead and do what you've already done and copy and paste the template there.
	Okay.  So first of all, if we're zero what should the answer be, we can read off test cases, better return the empty string.  And here, now, again, the trick I suggest is inventory with values that's what's up in the design recipe.  Suppose where N was 3, if N is 3 what's sub one of N, that's 2.  What is LOL star of 2?  It's, we have down on test case, and what do we need to get?  We're given LOLLOL, we're given the string to work with and we need to come up with the answer -- highlighting -- how do we get LOL, to LOLLOL, I'll string append and LOL on the front of it.
	And step 8 of design recipe -- look there, I left some parentheses out of my template.  All tests passed.
	Okay, awesome.  So again, the thinking is, the template suggested doing this, and it's okay, I'm going to start with a string.  A string that's almost all the LOL's I need.  If given 19, I have LOL star sub one ever 19.  I need to get 19 LOL's, string append one copy of LOL on the string I was given.
	That's the part, that a lot of people sort of get confused on.  They do don't believe in saying, the template gave me this string here and I can start with that string.
	You want to get a lot of work before you get to the starting point -- and that's not a good way to finish the race.
	Why does this work?  Because our code follows the template, the template follows data definition.  It's okay to be recursive in the same place the data definition is recursive.
	Okay?  By the way, in your discreet math class, what was you're favorite method of proof?  -- discrete math class, -- what was your favorite method of proof?  Hopefully, if nothing you read the book and got proof by induction, induction says hey proof something about 0.  Then proves in something works for N mean minus one it also works for N, that's same reasoning here, how can I prove this function LOL star works, I know it works for zero and assuming it works for 6, I'm sure this works for 7, if that recursive call gave me 6 copies I know I got 7 cop cope copies.
	If works for N minus one, then it works for that.  If you want to work through the proof and if N is 0, code works, if one does it work, well get string appended 2, empty string, if N were 2, then recursive call gives me LOL star of one, get the right answer for 2, if 2, 3?  If 3?  Right answer for 4?  You do that, and that's the idea of feeding out proof by induction works.
	Of course you don't do that proof by induction, just show 2 steps, write the code do these 2 things, assume it works for recursive call make it work for entire bigger structure.
	And this code, reason, induction works and based on data definition of natnum.  If you want to prove something, mathematical induction on numbers to prove things about all natural numbers.
	What if we want to prove about all lists of something -- all lists of strings or Booleans or numbers, you would use induction but use data definition for what is a list of numbers or list of strings and it will look (inaudible) to the code we're writing and that's structural induction if you do that.  Same thing for trees.  Proofing about all trees.
	If right data definition for trees you can use for all proofs an writing the code.
	Okay.  -- should we do -- a -- couple more, I'll leave it to you, if you want to figure out factorial, that's the one a lot of people use.  Let's do one more.
	Bulls eye -- takes in natnum and return an image so seen image working for homework 2, homework 3, and yeah, return a the image of a, I guess I don't need to say return image of a -- I know that, good programmer I would not need to repeat that.  Bulls eye target with N rings.
	Do that for function header, define bulls eye of N.
	First do check expects.
	Bulls eye of, let's do bulls eye of 3.
	And I want to get some image here.
	So first of all, to use images let me save this -- part 2, there we are.  What do I need to do to get the images?  Yeah I have to have this require to, to HTDP images, run, has a problem with the...., can I say circle 10 solid blue?  No it didn't like -- comment out that line -- there we are, circle 10 solid blue and get that, and I can say -- circle 20 of solid orange and get that -- what's the other thing I can do?  Combine the images, and one way I do it is overlay, overlay one image on top of another.  Copy paste here -- okay, I can overlay the blue circle on top of the orange circle.  Can you take this thing and overlay on top of something else?  I want to make a bulls eye, we're starting to get a bulls eye, this only has 2 rings, I want a bulls eye with 3 rings.
	How can I hand craft bulls eye with exactly 3 rings, using orange and blue rings there?  
	Anybody?  I have this blue and orange circle, what should I put it on to get bulls eye image?  Is it too easy of a question?  20 by 50 solid brown rum bus?  No.  A big blue circle, that big circle should be 30 in radius.
	There we are, okay.
	So, I like that, copy paste that, and go ahead and -- that's what I want bulls eye 3 to return.  And now it might be again, I suggested in homework last time to describe how you made that image.
	How?  It was overlay of this, this, of course that begs ever question a bit.  How did I get that one, that was the overlay -- of something N and something.
	How do I get that thing with 2ing of them.  Overlay of those 2 circles and how did the get each of those -- I like this because it forces me to have totally textual way, because my function will probably be totally text.  Doesn't have to be, but -- there we are.
	Okay.  So this is how I made that image.
	I can paste, sounds good, let me double check that really works.  Not even getting to that function yet, copy and paste this down to the bottom window from.  Okay.
	Da-da-da -- didn't load the image because we didn't get anywhere.  Oh, my goodness.  Okay, yeah, that last image is coming from this big overlay expression, so in all this, my copy and pasting I got it right, okay.
	Go ahead and -- let's see if we can write the function bulls eye, let's see how close we get.  How much of the function bulls eye can you write.
	Hint?  Wait, we have the template, this is function, process of natural numbers, we have template, go ahead -- put in the template -- we didn't get enough check expects, it the problem, right?  let me go ahead and bulls eye of 2 was this thing -- there we are.
	Sorry, should finish all any check expects first.
	What's check expect bulls eye one, that's basic blue circle, so put in circle 10, solid blue.
	No need to say how I got that, I don't have image coded.  What is, what's the other test case I should do.  Check expect of bulls eye of, we did 3, 2, one, better do 0.  What is pulls eye of 0?  What's bulls eye of zero?  One person typing, yeah solid white circle, sure.  Does the color matter if we have circle size 0, that is solid red, go ahead and do that, oh,  da-da-da, haven't finished template yet, if I look at circle with solid red, I draw that of size 0.  Man, this is killing me it doesn't load the library first.  If you do through menu command it does.
	Anyway, draws as nothing, could not (Inaudible) I can use, turns out there's a, constant in the language called empty image, and I could use empty image like empty list.  Now that we've done templates go ahead and write the, sorry, done test cases for 0, 1, 2, 3, now give me, fill in template to write the function.
	For zero easy, we write that in.
	Wait I minute.  Think of N being 3, if N is 3 what does bullseye of 2 give me?  This image here, how do I get, and I want this image.  How do I get from the smaller one to the bigger one.  N is 34, I want to get from the bullseye of 2 rings to bullseye 3 rings, I'm giving the bullseye with 2 rings, can't add one to image, can't say, add one, how do I use that small image -- yeah, overlay.  Yeah overlay -- that small image -- on to what?  A bigger blue circle, we saw here, took that part, overlay on to circle 30 solid blue.
	Okay.  Of course, not always 30 when I give overlay, circle 30 solid blue.  The 30 varies, when going from 2 to 3, that outside circle for bullseye of 3 was 30.  And if had been 7?  It would not be 30 it would be 70.  So -- yeah, not plus 10% but times 10.
	But I know what you meant.
	Yeah.
	So, just take, again think how do I go from, it was 30, from bullseye 3, I wanted to circle 30, for 2, 20, size 10, I see the pattern.
	Yeah I run this.  And now I can run it, and I get failures.  We can look at this here -- and yeah, oh, -- in fact, I never mentioned orange anywhere in my code so no surprise I didn't get orange.  I'm laying small bigger circle on bigger blue circle and bigger blue circle and bigger blue circle, not interesting.
	What do we need to do, just like we didn't always say 30, this is not always blue, it's some expression involving N -- right?  Can anybody tell me, I want to say either blue or orange, depending on -- yeah, even, I can use even -- and blue and orange, how do I combine those into a little expression?  So you use cond, yeah.  Here I'm going to use slightly shorter thing than cond, I'm going to use IF.
	If appropriated form of cond.
	If doing data analysis or doing template, processing union type, I like using cond if only 2 branches.  It had helps to communicate to others, maybe this cond here is handling union type, and it is.  Here trying to, trying to say -- is N even or odd.  So -- how does IF work?  I'm not sure if I showed in this section or non.  If you used in excel®, same thing.
	Function that takes 3 inputs, Boolean and 2 of anything.
	In this case 2 images, sorry 2 symbols.  The question is, is N even?  If N is even, what color do I want to use?  I'm not sure, but I have test cases, one was 2, I want to overlay a blue circle -- wait, bullseye of 2, I want to take the small one and overlay on top of orange circle.  So it's even I want to use orange, and when it's odd, otherwise I'll use blue.
	Now look, how does this look, I factored this out.  I could have put at top or circle, overlay in each case, overlay bullseye on top of a large circle, this is always the radius, doesn't belong in IF else statement.
	The only part that varies, third argument.  Going to evaluate either symbol orange or the symbol blue.
	See if it works.
	Read missing a bad closed paren.  You may have seen this before read missing -- close preceding.
	Go there and delete it, and move cursor back and forth and make sure everything seems there.  Yeah, seems to match up with define when I go to the end.  So sounds good.  Okay.  All 9 tests passed.
	You know what that means?  We can now call bullseye of 23, and that means we can take a break.  Because you're being hypnotized as you STARE in the swirling circle of life.  We're close to the break point.  Take 5 minute break.
	Back at 19:42, not 43.
	[Break Time].
	INSTRUCTOR:  Okay, Chris I was getting, if you have error, in like check expect -- it somehow doesn't, before it runs a single line of code it looks for a problem, like with a.... or template being empty or something like that.  Once solution might be if you go to, don't use the required 2 H 2 B image, go to language menu and use teach pack, I forget which one I suggested to use on previous homework, if you add as teach back, you don't have that problem, I'm not sure, there's some other error that's causing that -- to happen.
	-- wait a minute of bullseye of 0, should return an empty string?  That I think is a problem.  What is the return time for bullseye.  Takes in natnum and returns an image, so better return an image and never a string.
	Yeah.  So, we need an image that is totally empty but has to be an image.
	The reason is, we take that, when we make the bullseye of size one, we overlay the bullseye of size 0 onto it.  And again if you look on the, if hit on top of like circle or overlay and hit F one, the browser brings up documentation for that function, and, it's one big page that has documentation for all of the drawing functions.  If you look through there, we use circle of zero when we work through these to make empty image.  It turns out there's constant, called empty hive fen image --empty image.
	Yeah, like empty string, it's image.
	You can ask, what is image width of empty image.  Zero you can say, equal of empty image and circle of radius 0.
	And yup, true, the empty image is equal to the image of circle radius 0.  So, again, empty image built into the language same as string and empty list, built in the language.  Hard coded constant markers there.
	Da-da-da -- resume recording here.
	Okay, starting to record again.  By the way -- filling up water pot the it occurred to me one other thing we could do.  Keep the eye watching you guys, one other thing, here we went ahead and alternated between orange and blue.  -- and what if I want to alternate between orange, blue, pink.  I could do something if N was, N 3, or 7 colors, should I go ahead and -- go ahead and show you what occurs to me.
	Except I'm using helper function we're not allowed to use until you write it yourself.  So go ahead and make I little thing, go back to even and odd and stick in version here, after saying note, you can't use list REF until you -- can write it yourself.
	Which now you're able to, you have all the tools you need to, but I'll say, define all colors as being a list of orange and blue and pink and black and red and gosh I'm not sure a whole list of colors, not sure what the -- how complete it is, but a good list of colors.  Taken from a standard list for monitor colors, used fairly wide in the industry.  So, I'm not sure if those are done.  Instead of doing that, I'm going to say, list REF and I'm going to take remainder of N divided by, length of all colors, -- and list all colors.
	So, what color am I going to choose?  I'm going to take N is going be 876-54-3210 -- then, my colors are going to count down, if you choose number too big, I'll take remainder, wrapping around this list repeatedly, my check expects will fail now, but, oops, expect pairs -- given 1.  Swap the order of list and number.
	Okay, I get different things here but let me try, bullseye, what was the previous one I had.  Bullseye of 70.  Yeah.
	Okay.
	So, now we have, make a rainbow, if I put color of rainbow, salmon is a color, pretty awesome.  Anyway, that's side thought.  I like using lists, lists are awesome, throw things in lists and use elements of list rather than hard coding one or 2.  I'm going to leave that commented out and do this one.
	If you use the stepper for list ref, since it's built in it will happen in a single step.  Only functions you find yourself that get step through.
	So -- okay.
	So that was an example of another data definition for natnum and we went ahead and used it, and let me, take that out for now and put this, okay.  And so the question is, with this bullseye code here, that used orange and blue, how much did we have to add to the template?  We added the overlay, the circle, the fact that, N had to multiply by 10, that added in, the solid was new.  And then the F, but things that were from, requires sufficient calls, all of this structure here.  I guess the empty image we put that N but in particular, the fact we're overlaying on top of is slightly smaller case already.  That is the big huge win.
	And then how did we get other things right?  The test cases.  The fact we wrote test case for bullseye 3, if we could not have written that by hand, and figure out, 30 solid blue and here it was to get the other one, it was a circle of 20 solid orange and this was a circle of 10 solid blue, writing those down in each of the different cases that made me realize, I need to use, 30, 20, 10, I can figure that out.
	Hey, all, alternate between orange and blue that took a little bit much thinking, but was not too bad.  So -- I, if N is even do the other.
	So, the power of template gives you a lot of stuff.  And designer speed, going through test cases in that order.
	Being careful of what is bullseye of 0 that's not empty string and part of reason Chris you fell into that trap, is I didn't make you write that line.  I did step 5 A of the template for you and wrote that line.  If you wrote the line and bullseye and thought about the type it has to return an image, you'd be more on edge when writing the return type.  Way O wait a minute did didn't I write I had to return a string, hopefully.  All these steps in design recipe, each one helps you catch later errors that are good to catch.
	And thinking about what is the proper answer for, you know, a bullseye of size 0, has to be image, so.
	And that circle of size 0 did just fine.
	Okay.
	Let me -- go back to my commented out there.
	Da-da-da -- okay.  Third topic for the evening.  -- a lot of these things, I've weaving things together, pulling back and trying new topics and come in and weave back together.  We saw that with grammar, a lot of grammar rules were the same as what we're doing for lists, to say 0 or more or something, that was the data definition for lists, exact same trick there.  Okay.
	Third topic, function are values.
	Okay.
	And I think I mentioned this before, we talked about classes, categories of languages and people talk about functional programming.
	This is one of things people mean sometimes, that is we can pass them into functions as arguments and we might even get them back as a result from a function.
	Okay.  We're going to look at this first option first, passing function into other functions.
	Let's go ahead, we saw we had list conds.
	Cons of 3, cons of 7, cons ever 2, and empty.
	I'll name that list.
	Define, if I can spell define, define L 372.
	Great, turns out if I want to sort a list, sort is built into racket and I can call it.  Try this.
	Oh, doesn't have it built in in intermediate, so I'll bump up, I'll bump up to intermediate, we won't need this in the homeworks, you won't need to bump up for a little bit.  Okay.
	And here is error we get.  Sort, it expect twos arguments but found only one.
	And turns out, if you look at document for source, it wants list of items to sort and then says, give me, load a hi, hi to low, some other thing entirely, and I can go ahead and pass in a function, so turns out greater than is a function.  I can pass it in as my second argument to sort.  And we'll run this.  And the answer comes back as list 2, 3, 7.
	What is my variable hold, L 372?  What's inside there?  Is it, list containing 2, 3, 7?  Or 3, 7, 2, which order is it?  -- any guesses?  So, Sean says go either way, and in Java   what would it be?  Might be familiar with this, in Java when you call sort.  It changes the list and doesn't give you an answer.
	Here, let's go and, hit return and see -- 3, 7, 2.
	Here in, this is what I think is more important about functional programming, we don't modify our data ta.  If you have the list 372, you call a function and get new list back, but the first list is unchanged.  In the same way you take a string, even in Java, and convert to uppercase, the lower case is still there.  If you say name is BARLAND and call to uppercase, name dot 2 uppercase, you get new string, capital B bar land, but still have string bar land sitting around.  That will be the contents of name.  Because you didn't reassign to variable.
	Lists in Java are not like that, if you have BARLAND and you sort it, you change that, mutate that list.  Here is -- let's do a slightly different one.
	Define names to be, cons Eric, and go ahead and use people in the class, Steven   -- cons mark -- I'm going down the top of screen by comments window.  Skipping repeats.
	ASHENAFI -- cons Christopher -- empty.
	Close off that cons, close off that cons.
	Defined names and I say sort of names.
	Now if I wanted to sort names I can't pass in less than, if I pass less than, less than expects numbers but given a string like mark.  I want to compare these alphabetically, so I call string less than.  That's the function that takes in 2 strings and says yes or no, is one string less than another.  That sorts list a sending, if I change this to greater than.  Then I'm sorting descending.
	Okay?  Okay.
	Fair enough.  So I have different ways ever sorting the strings.  What if I want to sort differently.  I want to go ahead and sort, gosh, what's different way to sort?  I want to look at the second letter and decide, by the second letter and if you have the same second letter you're equal, so I define my own custom sorting criteria.
	So define, second letter less than, takes in 2 strings, they better be second letter less than string, string to Boolean, and really I'm going to make the assumption, things have at least 2 letters, so it makes sense to talk about the second letter of a string, let me call this string A and B, one and 2 is a little confusing.
	Take string A and pull out character index one.
	That's the second character, index one.
	Do the same thing for string B, and now, CHAR less than -- that works fine, should have check expects for this -- go ahead, check expect, second letter, less than of hello and bye, is E less than Y?  -- is E less than Y?  I think we talked about this before.
	Yeah.  And again, think where it is on the dictionary, E comes before.  These are characters but even on the ASCII chart.  Look for ass co value or uni code value I should say these days.
	-- ASCII --
	So we'll try that -- see if I pass my test cases -- yeah, both pass, E is less than Y, E accent (Inaudible) is not less than Y, all the special characters come later than the basic A through Z's, so.
	Uni cord, I can say, what is, is the Greek letter beta less than the (Inaudible) symbol for house, those are both in uni code, I'll get the answer, because uni code enforces something.
	Okay.
	So -- now, interesting thing, I can say sort of names and go ahead and sort by second letter less than.
	Okay.
	Here is the answer that I goat.  Is it really sorted by second letter, H is less than H, S is less than T, so that's cool, we sort and we can give whatever custom criteria we want to sort by.  Why?  We get to pass in just the not just string and Boolean, we pass in entire function and inside the code for force, it takes the function it was given and calls it when it needs to.
	So that's -- that's kind of neat.
	-- how do I do this in Java?  -- how do I sort, if I have a list of strings, I can sort in Java, there's function collection, it changes the list, it doesn't return a new list, -- how do I go ahead and -- if I want to have that list sort by the second letter -- of a string -- what would I do in Java, anybody know?  Pull up this Java here, don't need that, so I can say collection dot source, but collection dot sorts, I can't pass the math odd, or function second letter.  Okay.
	So it turns out in if I want to go ahead, here is Java code, can people read that, maybe?  -- I have stuff commented out.  Don't worry about that.
	I have array, array, not a list, can go either way in Java, -- bands, bunch of bands, cars, Bishop Allan and police.
	Can I print that list out and then I can go and sort it.  Here is how it works in Java, I say this here is Java 9, a little bit weird.
	Let me show, da-da-da -- arrays dot sort -- Bishop Allan is relatively new.
	I'm going to sort bands and here is how I do in Java before Java came along this year.
	I can't go ahead and pass code here.
	Java doesn't allow that.  What they do, they say hey go ahead and make a comparator object, and here is, I'll make, there's a class comparator out there, and it's actually abstract class, and I'm going to make one, class comparator is weird, only one method inside it, called, I think compare 2 -- I need to look it up, I think it's called compare, not compared to, I think that's confusing.
	Yeah, so I can go ahead and write my own comparator, my comparing gets new, comparator and comparable are different.  I think you're thinking of comparable that uses compare 2.
	New comparator, now, what is the -- syntax for anonymous function, is this the file?  I have in different file.  Let me pull that up in a moment.
	I think the file looks like this -- odd, and by the way, let me pull up my browser for a second here.
	And.
	Where are we?  -- I'll do a search for Java comparator.
	Text is too small for you to read, probably -- and it wants a method called come pair.
	So -- in particular come pair takes in 2 objects and returns int, (Reading), -- so here is what I'll do, pull up my, here -- new comparator and make this method called int, compare, might have to be public, public int compare, takes in comparator of string, takes in 2 strings, string A and string B I think we call them.
	Okay.  And what did that function do?  It went ahead and -- I'm never sure how to indent this stuff, I'm making new anonymous class in the middle of this file, right?  I'm making a new subclass of come par tore.  Subclassing without doing it in a different file.  So make a new comparator, have a compare method and I'm going to return string A dot care at of one is less than, string B dot CHARA -- I want to return a Boolean, int depending.  I think I'll say A minus B, I have to think about that, read the documentation -- so -- okay, here is the method, this method is sitting inside a class.  I just made a new class.  It's anonymous class, I just say, hey it's good to be extending comparator and stuck at inside my variable my comparing.
	And I need to say that.
	Okay.  Let's see if I got that syntax right.  Not a statement.  I need a return -- semicolon expected after everything.  I said -- comparator, my COMP gets some new things semicolon.  We talked about this example, for (Inaudible) in Java, ID and equal sign, semi expression and semicolon.
	Now go ahead and say sort bands and I can pass it my COMP, this compiles.
	I made, this is a lot of work, I wanted to know if one string was less than another by using the second letter criterion.  And I want to sort based on that, so run this, print it out what it is after doing this.  Now of course the second letter is a little weird, it's going to be HH, the word -- the -- occurring several times.
	Let's throw in the names we had a as well.
	I'll leave it like this.  This is good enough.
	Okay.
	I'm going to say -- FOO dot, what did I call that?  Stuff, going to printout, this, going to print it out first, gets the cars, Bishop Allan and the police, and then sorts by the cars, -- we actually can do this, in Java.
	Is it ugly?  Yes.
	What did we do?  Here is the important part.  Is, we could not, can't just pass a function in Java like we want to but we can get pretty close.  I can pass an object, object of a class that only has one method.  That's how I get the code, give the code to the sort to function.  I give an object that only has one method and both me and sort know that that method is going to have to be called compare.
	It's important I get the name right.  If I change the name, it's not going to work.
	So -- by the way, if I wanted to sort alphabetically, I can do that -- how do I want to -- first, this is old Java, okay?  -- let me skip straight to the new Java.
	The new Java, if I want to compare 2 strings by their first character, Java 8 added new syntax nor anonymous function.  Then go back to racket -- I go ahead and make a function that takes in, here is what I'll write, STRA, STRB, arrow, return, and copy and paste this.
	 -- I'm going to comment out this whole thing, this out.
	Okay.  -- I need to get this line -- out of here -- why is this not grayed out.  I'm a little suspicious.
	Oops -- small, STRB with a small S, this now does the same thing.
	This is a lot more amenable.  Right?  So oops.
	-- I get the cores, the police, Bishop Allan, good, that now works, wrong class, sorry -- this is a little more amenable.  I say arrays dot sort.  This is almost like putting the code here, why does this work in Java?  Here is the answer.  Arrays dot sort has been around before this new fancy Java, 8 came out.  Arrays dot sorts want something of type comparator.
	The thing that I, you know, wants something of that type.
	And here is what they added in Java 8.  When you go to compile, this says, I know we want something of type comparator here, comparator is weird interface, weird interface that only has one moth odd inside it.  And someone gave necessity (inaudible) code, I'm going to rewrite what we have highlighted and Java behind your back, rewrites as new comparator and uses name of one method inside that interface.  That's cool, very nice syntactic sugar option.
	I'm very happy to be able to write this.  Rather than all of this new comparator that contains one method.  It refers, it says hey, it only works because the type ox inspected by the function wants to be an interface that only has one method.  Okay?  So, -- if it wants an object that has 3 methods inside it, it could not work, it could not provide which one I was providing magic code for.
	There's a little more shorthand because the only statement inside here is a return, I can leave off the curly brackets, and, leave off the word return.  Hey, you know I think the people who are writing Java 8 had been looking how cool, closure was and closure is a list just like racket is, let's leave off.  If implicit we can leave off the word return.  We can have curly brackets an 10 lines of code, if all you have is one line that's a return, then you can omit it in this anonymous function, we call this anonymous function, why?  We never gave a name to it, it picks up that name from the syntactic de sugaring that happens, this is any place that I function wants --
	DIANA: Where did it go?  
	INSTRUCTOR:  I'm back now, bit of code -- okay.
	Yeah, so you would not leave -- just getting so interesting.
	This works not just containing -- which is kind of cool.  Let's finish with going back to racket and see how to do this in racket.
	DIANA: Not sharing and sound was going in and out.
	INSTRUCTOR:  Okay, audio, I'll go off and on real quick.
	 See if audio is any better.
	And, I'll keep talking so we can tell.
	Okay.  Oh, maybe, let me turn my WI-Fi off -- I think that was exactly it.  Okay, can you hear me?  Am I back?  So, interesting that, tolerates a small disconnect and disconnects on a whole different network.
	Yeah.  My sharing, when I lost contact, thank you.
	Okay, that's good to know.
	Okay.  So, let's go ahead and do this in racket.  So I want to go ahead and say sort.  The thing I want to change, I don't want to have to define the function up hire, and then, call it down here, can I do that, it works -- I just want to say, I don't want to give this function a name.
	Okay?  -- here is how I can do it.  I still need all the code like before.  I'm going to say open per ran, lambda, and this is, STRA and STRB.
	-- okay.  And this lambda keyword and open paren, that's equivalent in Java, that's equivalent of this STR, STRB and paren, this is how Java knew I was making a function, that arrow in between parameter list and code.
	Racket know it's, using prefix notation that uses lambda.
	The word lambda.
	Okay.
	And then I can go ahead and put this code that I had in here.  What's the only difference?  I'm not give thing function a name, ever.
	Still need to have the same code there.  -- in Java it was, Java A is what added anonymous functions.
	The whole functional interface.
	And again, de sugars to only features already there in Java 7.  The de sugar, anonymous new comparator thing.  Okay, let's run this.
	Lambda, found a lambda that is not a function definition, because I'm not in the right language level I guess, choose language, intermediate student with lambda, there we are.
	Okay, and now it did exact same thing.  Whether I gave it name second letter, or left it as this -- by the way if I look at names, names is still unsorted.  In the other order.  Yeah, so I can go ahead and make the function without having to give it a name.
	Why function are values?  It's the same idea, if I want to go ahead and pass a number, call a function and pass at 3, I don't need to take 3 and stick into variable and have variable in function call, I can say 3 right there.  Well, same, I don't need to take the code and attach to the name, second letter less than, I can just give you the code right away.  Okay.
	By the way, similar with names, too, this will not surprise you, I can go ahead and -- copy, paste, put these on 2 lines now.  Instead of names I'm going to take this cons, cons, cons -- and I didn't need to take that list of names and attach to list of names, to the identifier names, I can do this here.
	Coughing.
	So, yeah, I'm doing the same, same idea, and this is what I mean when I say function are values.
	I can use them like I use my other values.  I don't need to stick them in variables just pass to a function like anything else.
	Let me leave you with one last, 2 last things.
	Here is minor thing, you can go ahead and spell out lambda, there's a keyboard shortcut.  You can look this up in the documentation -- but if you want to hit on the MAC, it's command back slash.  It will go ahead and make it the Greek letter lambda, which is shorter to write and looks cooler.
	The back slash looks like backbone of this lambda, that's how I remember (inaudible) backlash, I windows I don't know what.
	Okay.
	One last thing -- if you remember, way back when, I talked about the different things we talked about in racket, we said there were 2 flavors of define, define for a constant like define names to be cons, cons, blah-blah-blah and then defining a function.
	How did we go ahead and, how did racket know the difference between these 2 types of functions?  Sorry the 2 types of define, what Q's, one is defining function and one is attaching name to a value.
	Of the 2 flavors of define -- how do we, how does it know which one is attaching name to value and which one is -- hey go create a function?  
	Not the dash, I do have dash on the name, but that's part of name of function.
	Yeah, it's the open paren, -- between the word define and new name I was making up, there's a parentheses, I'm going to be making a function before that closed paren is where I find parameters.
	Here I have word define and no parentheses, just name, identifier straight up.
	So -- that is all a lie.
	Here is, really only one true form ever define, and type we used up online 9 here.  Here is what really happened.
	Define online 14 is syntactic sugar and stands for this -- define second letter to B -- I left off lambda, that's important -- define second letter to B, this value here.  This value is a function value, it's the function that takes in 2 parameters called this, and returns this here, you know the body, except STR and STRB got replaced with actual arguments when it's called.
	So functions are values.
	I can make a function and if I want to, pass it directly, I can pass it directly like I did here, I can pass to sort.  If I want to give name to it, sure, define is one way, I can use web star to give a name to it as local name.  Here, when the stuff that we see in line 14, when you see that, that is syntactic sugar that gets expanded out to racket to lines 18, 19, 20, really there's only one version ever define, the version ever define that takes a value, identifier and matches them up.
	Separately, functions can be values and use lambda to create a function without giving a name.  And if want to give name later we can.  So often we want to give it a name they built that syntactic sugar into the language.  Is that kind of cool?  -- or is it kind of cool that it's about 9:30 p.m. and we're wrapping up -- (Laughter).
	I thought this was really cool the first time I ran across this.  Yeah, -- it's unifies a lot of things and -- being -- just being the fact that I can pass functions around like anything else.  That's kind of cool.
	Java now, picked that up, a lot of other languages started do it.  Lists has been doing it since 1965, recently did more languages, closure has got a lot of attraction on the JVM and they do this N in enclosure as well.
	One last thing, arrays dot sort.  If I do want to sort a bunch alphabetically, call arrays dot sort and turns out a few other ways to talk about things.
	In particular, -- you might sometimes see this double colon notation.  This means, go to class string and find the method compared to.
	That method is already built in the class string.  And that uses the compare to method for strings as a function that takes in 2 strings and returns a Boolean, which is exactly what this did.  This one checked on second letters, this does straight up alpha bell account comparison.  With Java 8, the added ways to find the names of methods that already exist.  So they added double colon notation borrowed from C++, so you can talk about, here is -- you know, the code that lives inside semi class.  It looks, like you're passing around that code, really as turning into something like either this or this.  Turns into something like that behind the scenes.  But I'm heap if Java does that behind the scenes, let he's me think I'm passing code around and that's what I want to do.  Handy in all situations.
	We'll see in space invaders game, pass functions around all of the time and get a lot of mileage out of that, okay.
	Go ahead and call it a wrap for tonight.
	The homework, see if you can get it done by the start of class on Monday.
	Get it done by then, that's the due date.  Send me e-mail if you have questions -- and, you can come to this breeze room regular office hours, or Saturday 2-3.
	I'll be in our usual virtual room here.
	Okay, see you next week.
	May you dream of bullseye patterns and anonymous functions.
	I'll go ahead, put them in different firms.
	I'll make a file that has everything, it will be posted on the lectures page.
	Okay.
	Take care.