October 19th 2015 
	PROFESSOR:  Hello.  Start to get setup here.
	Okay, D2L having issues today, is it resolved?  Now or people still having problems?  It's going slow and timing out as well.  So go ahead, e-mail me what you all have, if -- and then we'll submit to D2L when we have a chance.  Tomorrow night see if it's there.  In the meantime, just send me an e-mail.
	-- yeah, so, do people want to talk about the homework briefly before continuing on our topics?  Or do you want to charge ahead in high order functions?  Yeah, Sean, turn in what you can turn in, again probably we might be talking, people want to talk about them I'm happy to, there will be a solution set posted, I hope to have it posted right as the class started, but I didn't get it done, so it will be sometime tomorrow that it gets posted.
	If you have not been able to get everything done, turn it in but make it clear this is how much I got done before the deadline, and I'll take that into account and try to give extra, yeah.
	Okay.  So, no huge demand to talk about a particular problem?  Someone dying to know a particular answer?  Can't wait until tomorrow?  Now is the time when your brain are best ready to take in any advice.
	How did it go overall?  Besides Steven and Sean?  If there is questions, I tried to e-mail, tried to phrase it as clearly as I can, if there's something that you're not sure of, feel free to ask.  If there's something -- now I understand what he means and you have way in a would have made better sense to you, I'm interested in seeing that for my future writing problems and so on -- definitely say, here is such and such on problem number 6, I would have (inaudible) time.  Yeah, absolutely do that.
	So -- like I was saying, e-mail me what you have now, if you want to, people are still working -- make it clear what was done before the deed line, and after the deadline, it's, if you put off work or family time to get this done, it's not fair to those.  I'll get solution posted tomorrow and give partial credit for the other stuff.  Okay.
	Da-da-da setup sharing -- we'll start talking about high order functions.
	Clear up these windows on my desktop.
	And then pull up so I can see the comments again khar.
	What's the thing I should net do about the comments -- is there any private conversation, the chat should not overlap something, let me know, so I can make your screens better --
	
	PROFESSOR:  Thank you, recorded.  Should have that down by now.  Okay.  So, I just grabbed something from some old homework, we had function a long time ago did function monogram, couple names, returned a small short string of the initials.
	Can I turn off picture if it's interference.
	I never shared, thought I did.
	Hi.  We wrote the function monogram and had repeated code and realized if we have function initialized that got rid of repeated code and initialized, or monogram is short function once we initialized working.  So, okay.
	So now I want to go ahead and look at, I'm to go make lists of strings.  So, I'll make a list of stir 0, strs one, will have Hello, so tack Hello onto the list.  strs 2, Guten Tag -- Ciao --
	Okay, strs 3, -- child Guten Tag.  
	Mapping of functions over, over a list.  Over a collection.
	Here is what I mean by that in this class, to map a function over list means I have a function, I have a list of possible inputs I want to apply that function to each individual thing of the list and get back a whole new list of corresponding results.
	In particular, I would go, bunch of these here, if I have list containing 3 different strings, and if I want to say I want to map-string-length on to that list, imagine myself writing a function, map-string-length, I want to get back, a list of all of the results.
	What is the list of all the results at looking at string length of each of the 3 things in the list.
	String length, map over this list, what is my answer going to be.
	Is anybody there, did I get lost after Steven talked about static.
	Oh, no.  Okay, good.  Okay, I want to make sure, so, -- I have string Guten Tag, I want to match string length over that list, what list should I get back as an answer, mapping means a lie that function to each (Reading) the highlighted.  Get back a list of the results.
	There we are, couple things there, so yeah, a list containing, string Ciao for, what is the strengths length of Guten Tag, I'm assuming 9 from the answer I'm getting, so I want to put those numbers, each of the answers, 4, 9, 5 into a list.  So that's going to be cons 4 onto the other answers, 9, 5, what's that?  That's, cons of 9 on to the other answers is 5.  How do I do that?  Cons 5 onto the empty string.
	Okay.  So, map-string-length, I guess, would be function that probably does something like that.
	Let's look at different problem, go ahead and take, that function initialized that I wrote before.  Let me go and change this here.  
	Erase things, if you have good eyesight you'll copy the answer first -- so, this function initialized, meaning give me a word return the first letter down cased with a period after that, helper function we wrote a long time ago for monogram.
	Take that list, strs 3, that contains, Ciao, Guten Tag, and Hello, what should the answer be, if I want, take the function initialize, map it over the list containing Ciao, Guten Tag, and Hello.  Not meant to be a tough question.
	Year not understanding the question, try to, give me clue beside that, or what I can do -- remember initialize, going back, initialize this function here.
	Map the function initialize over the list containing Ciao, Guten Tag and Hello.  What would the answer be -- 30 seconds.  -- no typing, oh, no typing.
	Don't remember?  Don't remember what?  Do you remember the function initialized as, showing on the screen 4 examples -- take a word, make initial out of it -- 
	What is happening a function mean?  Mapping a function, apply function to each element of a list.  And, collect all of the results into a new list.  Yeah.  So -- if I were to, this function makes initials, apply that function to the list containing the strings Ciao, Guten Tag and Hello -- what would the answer be, what is initialize of Ciao?  -- 5 second question.
	Okay, what's initialize of Guten Tag?  What's initialize Hello, what's a list containing all of those results.
	That's what I'm asking, right?  Yeah.
	So -- does that make sense?  So -- what Aaron had, mapping a function meaning apply that function, map initialize over a particular list, okay, call initialize on everything in the list and give me back a list of the results.  Okay.  So in this case -- map initialize, I get back the list containing child would be me C, cons the -- that string on list containing G dot, cons H dot.  -- okay, does that?  Make sense of, do you feel comfortable with the term mapping a function over a list?  Done a couple examples, that he happen in list of strings, this is 3 --
	Some, if I want to have a function called map-string-length, go back to string -- string length, what does that look like, if you want to map-string-length, go ahead and see if you remember what data definition of list of strings, like list of numbers, right?  -- strings.
	List of strings is cons, is either empty or cons of single string on to some other bigger list.
	Cons tack one thing on to a slightly smaller list, you get a slightly bigger list.  So -- go ahead and write me the code for map-string-length.  Map-string-length, what do I want this function to do?  Test case here, have couple more.
	Once we have term map down, what does it do?  Map-string-length on to this argument strs, what is the signature of map-string-length?  Who can give me that?  -- someone else header of the function.
	Someone else start template, so map-string-length, give a list of strings like Ciao, Guten Tag, Hello, and get back a list of numbers, like 4, 9, 5.
	So header define -- map-string-length, and name for argument?  Need name for bunch of strings I'm good, comment, I call it strs, what I call it will probably be a plural noun, when I have a list, describing things in the list with the letter S on it.
	-- just like in databases.  Name for table is, whatever a single row describes that will be the name of the table except pluralized.
	Okay.
	So map-string-length of strs, what is this function going to look like?  -- this should be a, old hat.
	It's con with how many branches?  Yeah, exactly, how did you know that, mark?  It was a con with 2 branches?  un yon type, but some could be union type with 5 branches like stop light color.  Is this, why with 2 branches?  Either empty or a, what?  -- a cons, yeah.
	From the answer, from the data definition, it was this or that.  And there were only 2 choices, list of strings is one of 2 possible ways to make a list of strings.  Because data definition had 2 options, my con will have 2 options.
	Okay.  Somebody besides mark and Aaron.  How do I, con with 2 branches, what are questions for each of the 2 branches.  Yeah, empty question mark.  And actually for...., include question mark, what's the full exact thing I have to write?  How do I ask, empty question mark, is the question, how do I cause it to be asked, I need to ask is what -- 
	We're going to ask if the system event is the empty list?  Are we going to ask if the number 17 is the empty list?  What do we want to know, what do I replace.... online 67 here -- what does it get replaced with.
	List of numbers.  -- that's not going to compile.  I think have the word empty in there is important.  So I'll take dictation here for what the first.... should get replaced with.  I was given a list, is strs empty?  Is something empty?  And I was given something that was either empty list on cond, I know that because of list of strings.  So, what do I put here?  Empty of strs.  Right?  Actually call a function, a lot of people write empty, that's not asking, it's a function, but I never called the function, not getting Boolean back until I call the function.
	Empty of strs.  Okay, been over this, I think we spent 6 hours doing things like this.  You should be on top of this.  What's the other question we have?  -- see if we complete the template?  Somebody else?  You're all being shy tonight, probably thinking too easy, is it one of these or one of those, empty tells us it's one of these and, if you ask if cons, is it an instruct.  This is really, this is constructor.
	 I was given strs it's either empty or constructive list.  Is strs empty, is it con instructed?  What else do we have from template?  Should we have a thread branch to handle the case, no.  You're given a list of strings, if someone gives without list of strings, we'll go with a list of strings.  Either empty or cons, can't be 17.  Turns out if you fall o off the end of cond, somebody did pass in 17, neither of these would pass.  Think about Java, how does Java do that, if you have function that takes in string do you check to see you got integer or a list?  No the language enforce it's.  We take that same philosophy here, and off on the lectures page, there's a thing about contracts.  There's a way to make Racket, put this in comments, but if you want that enforced by the computer at run time, you can add that, it's called contracts and look on the lectures page, have a link with some examples -- you're free to do that.
	Java script doesn't do that, PHP doesn't do that, language that are not statistically type you don't need to declare the type of compile time.
	So, well, again for Racket there isn't a compile time per se.  There isn't compile phase just run it.  Java compile time, it does bunch of things if you try to pass the wrong type, makes declare types everywhere, if you try to use incorrect way, it catches very early, long before you start running the program.
	We can run this, if somebody calls map-string-length 17 we'll fall off the cond and that will cause an error, we have actually handled this error.
	If you wanted to, go ahead and have a third branch that was else, great, I won't require it, since the language makes falling off the end of a cond an error, we already have that error being handled with.  If you want to handle yourself to get a better error message, fine, but not required.
	Union make sure you handle every list of strings and that's why we need to take care of these branches, what else do we have from template?  Including template here.  We don't have template memorized.  Tattoo on inside eyelids, have this down.
	The entire design recipe, template, step 3, C or something like that?  
	Follow the link, top of every page in all of the lectures.  Pull out the 2 fields.
	Within this branch we have an object, hey pull out the fields of that object.
	Okay.
	First of strs and rest of strs, does this ring a bell?  Again we spent quite a bit on this, I expect us to be up, between now and, next time we meet, spend 2 or 3 hours going over every example we talk about in lecture, between this lecture and next, maybe not 2 or 3 hours, but go back to every example we've done.
	I'm presuming you're doing that for previous lectures.
	It's a little like, watching me code is like watching somebody ride a bicycle, he pushed pedal down and then the other pedal, and then turns and wiggles the steering wheel, I can do it, but not until you start sit down and do it, like typing these things, and understand why each word is there.
	What was the type of first of strs?  How do we know?  I can out wait you all.  It will be like soccer going into overtime, what is the type of first of strs.
	?  Yeah, string, somebody else, how do we know it's a string, where does it say it was a string?  Each line number on the screen telling us it was a string?  Line 61, data definition, I'm going to call some function for strings, in this case string length will play a role.  This highlighted part is a -- string so, it's true, line 64 told us argument strs was list of string and data definition for list of strings.
	This, cons branch if it was a cons first field was a string.  What is type of rest of strings?  This highlight the part?  Yeah, going to be list of strings, we know that from data definition, 2 things inside the cons and okay, if compound is struck -- pull out those 2 fields.
	And what sort of function should we call on rest of strs, that's a list of strings, my function handles list of string according to line 64, so design recipe says, 9 times out of 10 think about making the recursive call here.
	I'll go in the, put this across.
	The lines here.
	Okay, first of strs, which is a string, rest of strs was a list of strings, what is the type of this?  This gray thing highlight the.  What is the result of that recursive call?  What's the type.
	Where on the screen can we fine that answer.
	Yeah, list of numbs, how do we know that, map-string-length, call that function, we get back a list of numbers, yeah.
	Okay.
	Cool.
	This is the template this part should be automatic, you should be able to write this in about 60 second  , about as fast as you can type.  So, those are the steps of recipe, review that design recipe in the links of each page.
	Okay.
	Finish this function, map-string-length.  Takes in a bunch of strings, returns the length of each of the strings.
	What do we need to do?  First of strings, decided that's individual string like Ciao, okay, what do I want to do with Ciao, I'm given again, this link, I'll do this -- inventory with values.  For writing the function here.
	Map-string-length, think of strs being the list contains Ciao, Guten Tag and Hello, what is first, Ciao, I have string of Ciao sitting here.
	What is rest of strs was, Guten Tag and Hello, what is map-string-length of rest of strs?  That was, list containing 9, 5.
	And what answer do I want to get, answer containing 4, 9, 5, I have Ciao and list 9, 5, how do I get from Ciao and the list 9, 5, to get the list 4, 9, 5.
	Take Ciao and need to call string length from that, Ciao to give you 5 -- sorry -- 4 -- now you have for and list of 9, 3, I have 4 and list of 9, 3, how do I get the list 4, 9, 3, what function will take the list and tack one more thing on the front of it?  Add one, takes a number adds to number.
	I want I function that takes in list and string and gives slightly longer list.
	Yeah, that's what cons does.  You give single item and list it -- gives back slightly longer list.
	Yeah, that's what I'm doing -- I have, I have the list 9, 5, according to inventory with values, so I'll go ahead and call cons on those 2 things.
	And that should go ahead and do it.
	Again, that's our, design recipe we start with the result of recursive call -- again, Ciao, Guten Tag and Hello.
	The rest would be Guten Tag, what would the rest of the call.
	That would give me 9, 5, from template, started with string Ciao and list of 9, 5.
	How do I go to the list 4, 9, 5, in general not just cons 4, it's cons the length of first.
	-- results of recursive call.
	Okay.  Have that.
	What happens if I map-string-length on to the empty list?  Again, mapping apply the function to each element of list, if I have 0 elements on the list, oh,  apply the function to 0 things, give back a list of results, have 0 result from that, 0 work, oh, yeah, that's going to be empty list.
	Again, we talk about the check expect online 50, I didn't give the ones for 53, or 55.  I had those up there previously written and they helped us figure out the answer.  Okay.
	So this is map-string-length, let's see if that actually works.
	Let me -- everything else, get rid of.
	Okay, I'm going to go ahead.  Run, see if that works.  And, if all tests pass include the 3 we just wrote for -- for map-string-length.  Okay, go ahead and write map initialize.
	I'll give you a list of strings, I want a list of all the first initials.
	Give you list of 29 strings, I want a list of 29 results, call them initialize on each of those 29 thing.
	Go ahead and see if you can work on that.
	I'll give you 2 minutes, see if you have full answer.
	Let's finish one thing so you can talk.
	Let's talk about the type, what does it take in, what does it return.
	Map initialize.
	-- doesn't quite take in string to symbol.  Here is example, map initialize, initialize, look at function, what was the type of initialize?  Took in a string and returned a string.  So I gave it the string, Hello, give me back the string H dot -- yeah, so -- map, and again, I need to, if I want to map-string-length on to something, take in list of strings, if I want to map initialize, yeah, give me list of things, give me list of 29, I'll call initialize 29 times and give you back 29 answers all bundled into a list.  Doesn't return a string, it returns a list of what?  
	Remember I'm collecting answer from initialize, what is the answer from initialize, what I call initialize what type do I get back?  Scroll up and look at initialize, it gave back a string.  I'll collect all the strings all the answers into a list.  So I'll have a list of string.
	Yeah.
	If you look up, back on that string length, string length too in one string and returned a number.  Here we gave it a list, 29 strings and got back 29 numbers.
	Since initialize took in a string, returned a string, (Inaudible) get back a list of string, all the answers.  This signature matches up with what a single call to initialize would do.  Single call to initialize takes in one string and gives back one string.
	Map initialize, list of strings and get back a list of all the answers, another list of strings.
	Okay.  See if you can go ahead and write the code for map initialize, -- which should follow fairly directly from the template that map-string-length did, give you 2 minutes for that.
	Work on this in Racket, if not sure how to proceed, you're reading about steps of the template, and each step of the template -- people about done?  
	I'll go ahead and -- going through, you know, my thinking, typing speed, map initialize takes a list of string, data definition with list of strings, union of 2 types.
	Empty or cons, I know strs is either empty or cons, if empty, then do something, or is strs a cons structure.  If so do something else.
	With the cons structure I know I can pull out the 2 fields, first and last -- first of strs is single string, I'll call string function on it.  Probably initialized.  I'm thinking for this problem and rest of strs will be type of list of string, from here, what's the function it wants to take in list of string, map initialize, template says yes indeed, consider that, recursive call strong, may not always be there, but often it is.  Okay.
	And again, if I want it think about inventory with values and have test case that we did -- strs 3 was our list contains Ciao, Guten Tag and Hello.  This would be Ciao and what would map initialize of rest of strs be?  Rest of strs is Guten Tag Hello, and happen mapping initialize, would give back 2 results, G period, H period and list.  So I have this orange part, I need to go from having Ciao and other part to get cons of C, the orange part.  Go from Ciao to string C by call as initial lies.  -- and, okay now I have the string C and I have the list here.
	I want to tack this thing on the front of that list, yeah, that would be the cons.  Okay.
	If empty list, give me a list of no strings at all and I'll call initialize on every one of them and collect 0 answers in the list and that would be the empty list.
	Okay.
	So, hopefully,  once I said we have map initialize that does this, you write the template, that one test case would get you from inventory of values to get you from having this to this and say I need to call initialize on that Ciao part -- okay, let's go ahead and check this.
	Syntax error.
	What I'm going to do -- something has gone wrong.  Unmatched parameter, expected close paren to close it open paren.  If I go to the end, don't, count parens, I left one out.  Okay.
	-- what's wrong here?  I misspelled a function name.
	Run this -- and now, includes the one we made here.
	Okay.
	So again, what's idea of mapping?  Map sing common idiom.  Happens a lot.  You have list of I am inputs and wanted to do something to every one of them and collect all of the answers.  That's what map does.  Okay.  Yeah.  So -- how about this?  If I give you a list of strings I want to go through and get a list of all the second halves of those strings.  Okay, well, gosh I guess I start writing a function called map second halves, but, this is getting tedious and looking back at the code we wrote for map initialize and map string, first of all what parts, how many words did not come from the template?  
	Having a con with 2 branches, empty and cons that's all in template.  What's not in the template from map string.
	Rest of strs that was in template, -- calling string length, that was not in the general template for any list of function (Inaudible) there's 3 tokens.  3 little bits, add or specialty map.
	How about map initialize, same thing here, hey you know the fact that whenever we map a function on to an empty list, if there's 0 inputs an collect answers there's 0 answers, map, if doing a map, call it empty list, it's always going to be empty list there.  What do I do?  No matter what function you want me to call, I'll call on the first thing in the list, struck in the cons case -- and take that answer and tack onto the function of recursive call.  So cons is the same in all of the maps only thing that differs is what function do I call on a single item of the list?  That's really of all these map functions that's all that matters.
	So I'm going to say, write the function my map.
	And, gosh, what do I mean by my map.  It's going to be a map, you're going to give it a list of inputs an give one other piece of function, the function that you want called on each of the things in that list.  Remember last time we finished, function are first class values and pass them into code and get answer back from code.
	So, yeah, we're going to take advantage of that.  let me give an example.  Check expect of -- my map and, how about initialize.  strs 3, I don't know if too confusing to write like this.  Get back the same as, function we just wrote, map initialize -- strs 3.
	Or to put another way, go back and look at function map, string length or map initialize, either one, I'm going to, comment that out -- I want to be able to say, map-string-length of strs is call to my map and give it stature strs and what function do I want called on every element, string length.  Okay.  I want it be able to say things like this, in line 72, my map and give it the function I want to apply to everything in the list and the list of numbers.  The list of whatever, inputs.
	So -- I think of, of this map as sorts of, I'm giving you list of things to work on and hammer, your job is hit everything in that list with hammer and give back list of results.
	Okay.
	So -- something like that -- or equivalent, I want to make the right -- map-string-length by calls it more general my map.  Once we have my map, probably never bother writing out map-string-length.  We would just write this directly, map?  String length, whatever you want it to do.
	That make sense?  What my map is going to do?  -- define my map and, give function, function F -- return, a list of results of calling F on every element of inputs.  Yes?  No?  How do people feel about that?  Function my map, give function and list of in puts.
	Yes?  No?  Mind blowing?  Everybody too tired?  So should work, yeah.
	I think we can write this function my map -- and again, when programming this happens all of the time.  I'm writing, I don't know, HTML table or something like that or trying to render in browser, I have a bunch of ever strings and want to know how long is each string, call them so I can figure out how long each row will be, I'll call map and string length and give it that list of strings and get back the answer.
	Maybe that function I need to call maybe not strengths length but takes in string of HTML and how many characters get rendered so things inside tags don't show up on the screen, might be some special function, might be called map of length as rendered HTML and my list of strings, but it comes, have a list of things, I p want do everything single one and get back all of the answers.
	Okay.  How will my map work?  -- he well, I'll give you a hint.  It's just like map initialize, except what?  
	My map will bow -- oops -- map, map initialize, call it my map.
	-- what's only change I need to make?  -- I don't want to call initialize here, I want to call whatever I'm suppose to map.  We were given a function and whatever that function is we called it F, yeah, so, -- take the first thing on the list, call F on it, get back some answer, whatever answer we get back, in gray there, I call cons to tack that on to, the result of recursive call.
	So.
	Base case -- if I have empty list call F on nothing at all, take all answers and put into list, -- so, that part stays the same.
	Okay.
	So this is function that takes in, this is example, last time we wrote, talked about sort and passing of function of our own making, somebody else.
	Here is example, where somebody else calls us and they'll hand us whatever function they want and we'll go ahead and we'll just call it, open paren, call function, function we call, whatever F stands for, F stands for some function.
	Okay, let's go ahead and, do this, I went ahead and redefined map-string-length to be called my map using built in string length, see if that runs.
	I didn't call it inputs -- I didn't call it strs, I called input on this version, we'll talk about more about the signature in a second, I fix that name.  Now I get an error, the error is, my map, expected 2 arguments but found only one, oh, no, what's gone wrong.
	Really some sense, I forgot to write my signature and lost track of what I need to give to my map.  My map expects 2 inputs, function and, applied function to.  So my map, here is the list of all of the other inputs.  -- and I need to pass a function.  What function should I pass?  -- yeah.  I'll go ahead, repeat, Mark's previous answer -- yeah.
	I'll go ahead and call -- that's the function I want to pass.  Call my job was to get F applied to every element on the list, recursive call will give me a function applied to all of the rest of the numbers.  It would be handy if F applied to all the numbers because that will help me get F applied to all numbers.
	My map, pass along to recursive call, a co, run, all tests pass, including extra one we did, and including using my new refactored version of map-string-length.  What's another example we can do?  Map square root, cons 16, cons 25, cons 9, cons 2 empty.
	My map, there we are.
	When we do that we get square root applied to each of the numbers in that list and collect all the answers into their own list, let's continue, 4, 5, 3, and in exact 1.414.
	Okay.
	And again, since my mistake, bump the up to intermediate student -- prints out this list, but think of this as cons, cons, cons -- okay.
	My map is pretty cool, I passed function, I might pass of function square root, string length, other function initialized, so -- so that's -- pretty full.
	Let's take a break.  And come back, look at just, using my-max and, I want to use this other one I mentioned here.
	Beginner student, where was it?  Given a list of strings find all the second-halves.
	We'll do that when we come back.
	
	[Break Time] 
	[Break Time].

	PROFESSOR:  Okay.  So last week as I recall we talked about, I think barely mentioned using lambda to create functions.  In particular da-da-da, here -- recall -- we didn't mention triplify before --
	One of define was, same, value, one was defining function given up the name.  Here we make the function and call it triplify.  We saw, last time, saying, really there's one flavor the define, is syntactic.
	Sugar for -- triplify, -- really just going to make some value here, and say this value is, now going be attached name triplify.  Just like define pie to be 3.14.  Define alien to be 50.  If you see the name alien with you use 506,789 to define triplify use blah, what do you want blah to be?  It has to be a function.  So, we can go ahead and --say define triplify to be this, the keyword lambda, we mentioned that barely, right?  --I think we mentioned it and sort of said, think basically, you know, gave this, gave a couple examples.
	Oh, lambda of N plus, hey this is a function that has N as parameter and what you call it returns plus of NNN.  Yes,  sort of anonymous class, -- except not really class.  We did talk about how in Java you can't pass code to sort, you have to pass an object that contains that, doing anonymous class has helped us, and -- in Java -- yeah, it was, a -- let me just see out here.  -- command back slash or window back slash.  Gives lambda character to avoid spelling out Lambda, you spell it Lambda or use that one Greek character, which you can paste in, look on Wikipedia for lambda and paste into file or you can do that, command backslash -- in Java,  and in Java, I should say Java 8, we have anonymous functions in Java 8 -- which I forget how much we talked about that, if I sort of, I didn't use this example triplify but Java 8 has new notation of the right arrow and places in Java where you can write this and looks like you're gust getting anonymous function.
	Take a function and takes N plus N plus N and didn't give it a name.  Just here is the function.
	If I did want to give it a name I could do that up here.
	So.
	In, did not mention before, but, in Java script, -- go ahead and write that.
	That makes anonymous function -- in Java script you can say, hey -- var triplify gets, -- and now becomes clear, this is just like I'm showing here for Racket, make a new variable, called triplify, and initialize that variable, initialize to hold this thing here.
	And this thing here is, -- a function that takes in one item and returns that item -- (Inaudible) coughing.
	These are all, --
	(DIANA: Lost connection)
	(-- back on --)
	Define, anonymous function.
	Somebody got locked up there?  -- sorry -- that may be my Ethernet cable pulling a bit, not sure.
	So -- Java script we can do the same thing, writing in Racket, Java now has it.  Basically Java, is like WOW, languages getting a lot of popularity, better add something to our language that can do it.  Where did Java get it from, maybe from list back in 1959, so, slowly other languages have caught on and it's mainstream to use lambdas.
	Okay.
	So, okay.  -- that was reminder that, -- define for a function is really, there is no, as soon as you write that, define for a function, where it turns into primitive underline simple define, the idea was function are values.
	Okay.  Yeah, triplify happens to be bound to something that happens to be a function value.
	I did not talk about in Java 8, turns out, that notation is, -- Java that is syntactic sugar for creating an anonymous class -- with one named method, where the above lambda-expression turns into that named method.
	So I want to discuss that more and most people are really interested -- but yeah.  It turns out Java they go the other way, also syntactic sugar, anonymous is syntactic sugar, it turns into making an anonymous class meet some interface.
	Infers a lot of types, if calling sort, and giving it array of strings, says sort for a race of strings, wants to be given -- gosh comparator object.  Compare to strings.
	It has only method called compare to.  Your lambda expression in Java, you'll see this stuff here and say, they want compare ton object with an object compare.  With method called compare, I'll go ahead and make that anonymous object and only one moth he had inside that compare I'll assume this is the code they want to use for that one method.  So, Java does it as way to hide ugliness of having to make anonymous subclass.  Or have to subclass this other interface just to pass a little bit of code   I really like that about Java.
	Okay.  -- and, the weird thing about Java, looks like I'm not mentioning any types, which is not Java, does not fill Java at all, really it has to be able to infer the types.
	Anyway, don't worry about any of that.  I want to O you to understand, have the variable called triplify, thing bound to is not a string, it's a function.
	Okay.
	Now, get back, I want to given a list of strings I want to find a list of all the second-halves of the strings.  So, I'm going to call my-map, give it some function that pulls out second half the a string and whatever, strs 3, that has Ciao, Guten Tag and Hello.
	-- expect cons Ciao, second half the that string was AO, cons of Guten Tag was 9 letters long?  I'll say the midpoint say round it down -- so -- take 4 and up, GUTE -- tag.  Okay.  And cons of Hello second half the Hello, rounding midpoint down -- okay.
	So, gosh I guess I could go, turns out I look from documentation, no string gives strings and gives back second half.  What do we do.  I can go off the right and write second half the string function and make test cases -- yeah I can could R do that.  If simple task and I think if I'm feeling gutsy and want to do this without any check-expect, I'll make that, (Inaudible) not going to name it.  Okay.  I'm not going to name it, I'll say write a little function, takes in one particular string -- and finds it second-halves.
	That's the function I'll give to my-map.
	So this is a very, typical use case for using lambda.  Calling map, my-map, and want to make a function, small function, you don't have to define and giver a name.  Just say I'm going to put the code right here.
	What is the code for the second half?  I'll call sub, string -- substring str starting halfway through, and it's going to be -- quotient of string length of str, 2.
	Okay, looks like this, define help every function called second half the string and this gray part is what the body of that function would be.  Take substring, look for one index where to start from and take all the way to the end.
	Yeah, substring of sub str, divided by 2, take co quotient that rounds down, during exact division would give me fractional amount, I don't want to do that.  Go ahead and run that.
	Okay.  Da-da-da.
	My-map -- my bad, go up -- move that down here.
	Down below, there, sorry about that.  Okay.  And, for the test path.  I didn't add new test case yet.  Here is the result of that expression and exactly what I wrote, expected output.
	So -- so does that make sense?  -- my-map, give it a function, function like square root built in great, say square root, if function written previously, initialized, great, mention initialize, if not written yet and don't want bother name ting, go ahead and put this here, a lambda expression.
	Thing to note, I need to say, need to name the parameter, str in this case, and give the body.  Really a function definition only has 2 parts.
	What's parameter and now they told me parameter, what's the body of the function.  That's all the function definition really is, those 2 parts.
	Okay.  I can turn this into check-expect now.
	Okay.  -- any other -- functions we want to do?  -- one more -- power use case?  All show this, what about -- taking strings and up casing each of them.
	Okay.  Problem -- up case string not in beginning student.
	Solution -- we'll write it ourselves using string to list, okay list of characters, -- returns list of characters, and -- string which does the opposite, takes list of characters, and makes a string out of them.
	So probably, describing them, almost the, signature almost more descriptive than trying to say in English.  String to list goes ahead and takes, string gives corresponding of characters an string does that opposite, reverse of that.
	Let's go down here, and say string to list of -- Hello -- and I get a list with character H, E, L and so on.
	And if I say string of cons H cons I, empty, oh, da-da-da -- check this out first here, function calls list to string.  Okay.  String   list and list to strings.
	-- and then there was the function up case CHAR -- works on string the character.  Okay, CHAR, lower case H.
	CHAR up case -- yeah, CHAR up case.
	The reason I tried on bottom window first, so I have that part nailed down so I can call helper functions with confidence.
	When writing code.
	Okay.
	I'm going to call some function to up case all of the entire string.  I expect to get back the list containing the strings, Ciao, and Guten Tag, and Hello, -- okay.
	What function do I want there again?  I can probably name it, it might be involved enough worth naming.  If I were doing this I probably would say no, no, convert string to up case -- I can do that.  And you'll see in a second why this, -- give me one string and, fill in.... with code that takes an individual string and converts it all into uppercase.
	Okay.  What will I do, call string to list of str, this gives me the list of characters.
	And I want to convert each of those characters to uppercase, how do I do that.  CHAR up case turns one character into uppercase, if I have a whole bunch of characters and want to convert all into uppercase, what function should I call?  Char up case turns single, if I have whole list of Chars, what should I call to it have that whole list uppercase, hint this is the whole point of the last 30 minutes.
	-- hint, starts with my MA -- yeah, my-map.  -- I have a whole bunch of list of characters and want to call a function own Eve of those, Char up case.  Yeah -- okay, take the list convert, take string and convert to list of characters, call up case on every single one.  I have a list of all uppercase characters, what do I want to do with that.
	List string -- this is a function that takes a single string and converts into upper indication, I hope.  I have not tested it.  I am a little kooky not name ting and letting myself, I'm going to test that by mapping on to 3 individual strings.
	So this is called my-map, but contained lambda, that by itself (inaudible) call to my-map.  Some people might call this a nested loop.  Let's go ahead and give it a try.
	strs, strs 3, I think I was calling that list.
	Okay.
	Okay.  Got back this list here.
	Yeah it really worked.  I'll make that a check-expect.
	Okay.  Questions?  Thoughts?  -- so the fact that I'm using, again, what I want to emphasize, call my-map and pass lambda and write down that, just write the code and not give it a name and make it a whole separating string, make anonymous function and put it right there, people do this all of the time.
	Sometimes, pass to my-map, is like initialize, a helper function that you wrote, sometimes just go ahead and do this, if it's a short little bit of code, so.
	Twisted part in doing this little bit of code for single string, I treated single string as list.  I used my-map inside of there, but that's extra gravy.
	-- so, every week is a reading week, right?  -- unfortunately we have 14 weeks and full 14 weeks of material to cover.  So not able to, I wish we had like a, Thanksgiving week, I guess, which is not really off because everybody is busy with family doing stuff.  I wish we had a fall break in the same way we had a spring break.  Okay.
	What I do want you to be able to think about, say hey, I can make a lambda expression and use it appropriately, when calling my-map.
	Okay.  Just to finish off -- my-map is actually built in as map.
	So, -- just call map, and -- pass function.
	This is really handy, coming up a lot.  You'll a realize in Java, start doing this about a quarter of the loops you write in Java, process loop and process array are doing a map.  You're going over the list or array and building up new list or new array of all of the sorts answers.
	And using back for later tasks.
	That's why map in particular is a powerful idiom.  In Java they don't have map per se, but Java 8 now has map, but you'll realize, in the loops you're writing you can now name some of the loops an say, hey this loop is doing a map.  We'll talk about filter as well, we say that loop is doing a filter, -- and those actually between map and filter, that's a lot of loops that you, in Java and now have better understanding.
	You're just say I'm writing a loop, and now name for certain idiom of loop that you're writing.
	Okay.
	I want to switch over -- and talk about the next topic.
	See if I can open the next file.
	I think it's on the lectures page a well.  Talking about tail recursion.
	There we are.
	Here we are.
	Okay.  
	So, this is just another example, if we're spread over 3 days, yeah this is a tough class to take, 3 hours in one evening, it's definitely mind numbing.
	Okay, I'll have those right after -- I'll have those right after lecture or during break.  Okay.
	Going day-to-day, I would start out the next day reminding us about map.  Here is function I call string to number.  Here is the list with 3 strings, call string to list on that and get an answer back.
	I should say that, in the intermediate student not be allowed to us this for the next homework but after that you can use it.  Function list that takes in 5 things an makes a list of 5 things, easier than typing cons, cons, cons, I want to get used to that for next homework, because in code cons is what you almost always want.  For test cases almost never useful inside your other functions.
	Notice here, using only to make test cases.
	Type that out -- copy, go down here -- and I get a list with, 3 numbers in it.  Why, I had a list of 3 strings, had hammer string to number, Alabama bam collected 3 results calling string to number.
	Okay.
	Here std new function I want to write.
	It's string append WOW.
	And it's going to take in a list of strings, back off not using map for this, we'll use, go back to designer string, give me a list of string and I give you back one string, where append all of the individual words, and add the word WHOA at the end of it.  String append, contains hi, bye, allow ha, -- if I give you empty list.  The answer is just WHOA, one thing to pay attention, is where spaces are -- so -- okay.
	How do we go ahead and write this function, string append WHOA, whoa -- I won't go through the ked, like other examples we've already done.
	String append whoa, give a bunch of strs, strings, empty, the answer is whoa, otherwise, go ahead and, hey string append whoa on the rest of strs, that gives me all of the other.
	I was given a list of one hundred strings in it, this is the other 99, remaining 99 turned into single long string with the whoa at the end of it.  One binge long string, first of strs single string.
	So I have 2 hinge strings so I need my full answer.
	If I had bye allow ha whoa, and string hi, how do I get to/-- call string append, first string and I space and that results in recursive call.
	Okay.
	Find all is good.  Go and I want to -- comment this part out.
	I want to go through this with a stepper, figure you did stepper last time.  Make sure nothing else is in here.
	-- that will -- aloha.
	Okay.
	I'm going to go through, get rid of that, Cal to map to string.  I don't care about that.
	I'm going to go through this with the stepper.
	Step button, make sure we're not overlapping the chat window.
	And I wish I could make this a little wider, but trying to keep the text large as well.
	Okay.
	So we have our definition for string append whoa, you see it up from, indented, and then down below, left-hand side, last 2 lies are test case, string append whoa, list -- okay, again remembering the stepper, we go from green to purple every time I press step it will slide the, which is currently green will get slid off and purple will get on the left-hand side and new pain, it does it all at once, that's mental image.
	First we see green go to purple in single step.
	String append whoa, that's just a variable, what variable that stand for?  That purple lambda, this is one step the computer does, when it sees a name, replace the name with whatever was associated with that, the value of that identifier.
	The value of identifier is big lambda expression.  Sounds good.  Questions on that?  -- shall I press step?  I know you're back at home saying press it, press it now.
	Okay.
	Okay, we see this.  And now, we have lambda of strs applied to the list, and I think we saw this step last time as well, how, what is the rule for applying a function?  -- okay.  Take the body of the function but big con statement and paste that as my answer, except, strs, replace with list of hi, bye, aloha.  Go from green to purple and have huge list, here con it empty of list, and cons -- do single step empty of this hi, bye, aloha will be false.  We have what is the rule for con, you can be question, answer pairs, if that thing in that question part, going to false, throw that branch away.
	The green part, with the first branch is cond of faults an whoa, simplify to, know that -- first question -- default, cond of remaining branches and only one remaining branch in this case.
	It becomes true.  The rule for cond when you see something true, take the whole answer, the right-hand side for the branch that evaluated to true.  -- okay.
	-- so the answer is now just the string append.  So string append of first of list hi, bye, aloha.  Hopefully these steps make sense, first returns high, string append of high, space and recursive call, string amend of hi and recursive call, do one more -- evaluate the rest -- I wish, eventually call rest of list hi bye aloha and get the list bye aloha.  And make that recursive call, let me hit step a few times.
	We do stuff, and this turns into string append, the recursive call turned into string append bye, we have first appending, string of hi, can't finish until has first argument, but something is string append of bye and space, something, another recursive call, step through that, building up these spending recursive calls.
	Okay?  -- we get through, we have, string append hi of, still waiting, for string append of bye and something to finish, that waiting on string append aloha, the other is rest of list of aloha, that's empty list.  That's going to, few steps again, work off bottom of window a bit.
	There whoa are.
	-- we're going to come down to the base case.  And we're going to get this.  String append the answer -- string append of hi, with string append bye and string append aloha.  And finally whoa, and now we can start unraveling it.  This moment there are 3 pending calls to string append.  Waiting around and waiting for this argument to finish evaluating.
	And now we pop out, pop out of it, step-by-step, allow hey space whoa, gives single string, string append bye space on the front of that, string append bye space on that, and we have our answer.  But here is what I want to, oops go back to.
	I want to go back to the case where we saw, we had 3 string appends pending.
	If list of one hundred strings in it, I would have one hundred pending calling to string append, okay, is that bad?  Not too bad, I mean certainly works, -- but, what happens every time you make a function call inside, you take computer architecture or something like that, what happens every time your language makes a function call?  -- inside the computer, to the hardware, what happens.
	Things get pushed on run time stat and goes and saves a bunch of stuff and keeps internal stat.  If you have list with one hundred strings great, but run time stack will built up one hundred times stack, each is pending, can't complete until recursive call finishes and then comes back.
	And yeah, if my input is too long and stack is finite size, in fact when you run Java often, can provide a flag, how many memory do you want to (Inaudible) space, one megabyte, if you have one megabyte stack space, if you try to process a list of more than, one hundred thousand items, it will (inaudible) the stack.
	Let's go and, close this stepper here.
	-- let's look at corresponding Java loop.
	-- okay?  And I claim this Java loop is not built of stack frames.
	I want to concentrate why is this the exact course respond dense to the Racket code, try to make correspondence closely as possible using available able names -- sorry this one doesn't correspond yet, it does act differently, not building up stack frames where Racket version D some stuff is still there though, still my base case, here is my Java for string append whoa, left the name strs the same.
	What do we do in Java, start with the string whoa and go ahead and, while my list is not empty, I'm goo to go ahead and, take my result so far and put that word onto the front of it.
	Okay.
	And then, I'm going to go ahead and take, strs, just go with process the first word on the list, now process the rest of them.  Okay.
	So -- strs gets, strs, people see the function sub list before in Java, just like the function substring except works on list, I want index 5 or 7, or just 5 all the way to the end.
	If you have a list of things, say sub list from index 5 up to index 9 or just say sub list of 5 that will give you 5 to the end of the list.
	Sub list strs dot sub list of one, that's, list strs from not including index 0, but including index one all the way to the end.
	Oh, that's the rest of the list, this is Java for the rest this is not quite how you write in Java naturally before seeing this, but this is the version I want to look at.
	Iterate through a list, go through the list and at every point say, hey throwaway the first thing in the list, strs gets the rest of the list on there.  Okay.
	And then, has this thing we don't have in Racket, go backup to curly braces an repeat, and keep repeating that, while the list is not empty.
	We did have the fact when the list was empty we had check for base case, we did have base case of whoa in our code here, and we did have, string append of first with -- space, on to something, and we did make a call to rest, so there are different correspondence here, not perfect correspondence -- because it does process in a different way.
	Okay.  And why does this loop not build up stack frames really internally the while goes to assembly code, hey go through and do this, and don't call a new function, go backup to where you were, except variable results so far as changed and variable strs has changed.  Assigned each of them inside the loop.
	Go back and do this again, but have a different result so far and different strs and then do it again.  Hey, do again with slightly different result so far and slightly different strs and do that while strs is in empty.
	I want to write this in, I want to write this Java code, I want to do something very similar to Racket, get as close as I can to this.  I'm going to add new variables called results so far and strs.
	One thing stuff that I don't have in Racket is a while loop.  so gosh.
	I don't have while loop in Racket, all I have is functions, tell you what, I'm going to make this while loop, I'll make that a helper function.
	So let's go ahead look at this.  This is whether I want to do.  I'm going to call my function string append whoa 2.  Works just like before, same test case, okay.  Okay.  And, going to have helper information.  String append whoa 2, is going to call the helper, SAW 2, saw to help, and I'm going to pass that list of strings and pass at results so far.  I had 2 variables going on in Java code, and strs, I -- trying to make code as similar as possible, so go ahead and have 2 variables going on in my, it's -- as much as possible to see both on the screen.  Go ahead and have 2 variables called strs and results so far and all I need to do is say hey, call the main function and initialize results so far to whoa, helper function is 2 parameters and results so far I pass in whoa as the initial value. 
So wrap helper function   and very first time I call helper function results so far is whoa.
	But now, that, while loop I have, now that's what the help saw 2 help is going to be, except not use while loop.  I'll good through and say, -- cond, empty of strs, something -- oh, -- check-expect.
	-- okay.
	I'm going to have my cond, going to have a, cons of strs, going to be different not follow template this time.  So -- I know you're thinking, is make going to follow template, finally get the is it stick where he had it.  Loosening up a bit.
	I'm doing that because I want to follow this Java code as closely as possible.  because I like Java code didn't build up a bunch of pending calls.
	Okay.  strs results so far, up in this Java code, when strs is empty, what did I return as my answer?  -- when strs became empty what was the answer to my function return?  
	Java code you have a loop, when strs becomes the empty list, what -- what does the function return?  -- doesn't return the empty list.  Again in the Java code.  Line 42, and strs, what strs became empty, then we didn't go through the while loop.  So -- which   strs was empty, list file failed and line 46 return results so far.  We do the same thing with code in Racket, when strs is empty, we give results so far.
	And you know, sort of see that in Java, because results so far is holding up string that got longer, longer, longer and finally finished loop and okay here is my final result.  And we're going to do the same thing.
	No.  Results sow far started with whoa and only got things, only got longer from there.
	So, strs had, if strs had again, hi, bye, aloha, -- results so far, after one time through the loop it will get, hi, it will be hi whoa.  -- and then, we'll make our, take, throwaway the hi, and go back again, strs is now, by R bye aloha and results are hi (Inaudible).
	Sort of saying here -- tracing through -- strs and -- result so far.
	And result so far, strs says whoa, and I -- hi, bye,  aloha, yeah, it's want to understand how this Java code is working.
	So it can make Racket code look similar.
	So yeah.  Before the first time through the loop, it looks like this, after we go through the loop what is result so far?  -- and what is strs?  --after go through the loop once, result so far gets strs, was hi, take that append to result so far and here is new report so far.
	And strs, sub lit from one onward, so throwaway, one index 0 and take the rest of it.
	Okay.  And then next time through the loop.  -- there's strs, what is strs dot get of 0, it's bye and make that new result so far.
	Okay.  And then also update strs, should have swapped the order of these 2 columns.
	Okay.  We go through the loop again, strs is not empty, so go through the loop.  Take strs dot get of 0, that's aloha, aloha string a spend space result so far -- that's going to give us, that -- and at this point, strs now has -- strs gets from, throwaway index 0, keep all the rest of it, and at this point, our while loop.  We go back to the top, our while loop strs is empty,  so we leave, lever the loop and return aloha by hi whoa.  Okay.
	Are we all good on that?  Did that help to work, walk through that.
	So, I want to do something, the same thing, in my Racket code, move that trace up above the function for the moment so that he with get as much onto the string as we can.
	Good.
	Okay.  So my list was empty, return result so far.  When the list was not empty we went through the loop.  We changed what results so far was, and changed what strs was and went back to the top.  Going back to the top, I'm going to say, is making the recursive call.
	Now I know you're thinking the whole thing to do this is avoid recursive call in the stack, -- hold on.
	Go backup at the top, the only difference is strs is a little different.  strs I want to do this thing here, instead of when I go backup to the top, what had been left of the strs is new value of strs.
	Make recursive call but pass it, rest of strs and results so far, what had been, had been that, when I go back to the top I want this to be my new version of results so far.  So -- string append of -- first of strs, result so far.
	We put this so now visible -- on there.
	So, I claim this, does the same, it's going to be, spiritually doing the same thing in the same way.  Going to say, hey go ahead and -- go backup to the top, but for strs use rest of strs an result so far, use string append of blah-blah-blah.
	So, I claim this morally is the same as that Java loop.
	Okay.  And here now is the key observation.  When you call this your now, think of computer hardware again.  Call this function, and, you're (inaudible), saw to help and has space for parameter strs and results so far and comes up and says, if empty do this, otherwise make this recursive call, so you could go ahead and make another recursive call and put 2 things on the, put 2 things, 2 values there on the stack.  Updated strs and updated results so far and make recursive call and have stack like before but here is clever observation.  Whatever that recursive call returns is exactly what, we returning.  That is when I make that recursive call to saw to help, we're done, I have my final answer.  Subcontract out to help per function, helper function gives back -- we'll buy pass the middleman, -- we're going to say, for that recursive call, don't make a new stack frame, wipe out -- the current stack frame and where I had on the current stack frame where I had strs and results, make this the new strs, and make this exception the new results so far and use the same stack frame. 
	This is optimization the compiler can make when generating machine code for this code here, -- hey you know whatever helper function returns, this function will never come back to this function, I need to remember it's local variables, it's done.  By the time we come back it's totally done.
	Okay.  So -- don't keep track ever it's local variables wipe out local variables and don't use the new stack frame.  I claim that was machine code generated for this Java thing, right?  But Java code we had a couple of local variables, results so far, strs, we wiped out those 2 local variables didn't add new stack frame.  It's at top of code of function again, and here, stack frame, reuse that statement, stack frame, Java never think of it as making function call -- but we're doing the same thing, we have the same 2 things in memory and hitting them, writing them repeatedly, same 2 local variables.
	That's the optimization that can happen here, good compiler can see, will not generate immediate stack frames.
	This version saw, string append whoa 2, -- this one you can have a list with one hundred thousand strings and will not generate a bunch of pending stack frames.
	We'll take a break and go through the stepper and see that, I'll verify it doesn't build up stack frames.
	Okay, let's take a break and come back to that and wrap up.
	 this idea, really how, recursion, how loop are a special case of recursion.
	Okay.
	Until 5 minutes to.  I'll get water, if you have questions typed in I'll answer those.

	[Break Time].

	PROFESSOR:  Okay.  Start going back.  There.
	So, what did we just talk about?  We saw, a process, a while loop in Java and how to process of list.  No not by making recursive calls so not build of stack frames tried to write Racket code to emulate that.  Say while err is heavy enough, it can generate the same assembly code that the Java would generate.  So -- and, do that by going through and --da-da-da -- run, -- run this -- test cases -- okay.
	In fact one thing we realized is that there's a difference between how my first version of string append will work and how this one works.  This Java program worked.  Our first version said, string append whoa, of hi bye, aloha, would give the list hi, bye aloha, whoa, that's not quite for Java version, -- what we got aloha bye, hi whoa.
	-- so, we'll come back to worry being this.  But, we actually ended up processing the things in the reverse order as you go through the stepper you'll see why that is.
	Okay.  So I want to go through using stepper, drive everything, setup there.
	I don't want the original string append bye hi, bye, comment that one out.
	Go ahead and keep this code nearby, keep it handy, I guess it will be there in the stepper so we'll see.
	-- move off check box.
	-- okay, what's going on here.
	Doing a bunch of stuff there.
	Skipping my -- comment out all of this -- here is one that I want.
	Comment out the whole rest of the file, by the way in Java, when you want to make, big huge chunk of file everything halfway through to the very end, maybe, that closing bracket, what do you have to be careful, use slash star and then slash star, a why does that not work in real life.  Put a slash star, halfway through the file, go to the end before matching closing brace and say slash star and doesn't actually comment out most the file, why not, in real life?  -- I'm sure you've seen this before.  What if second half the file, people had regular comments, no problem.
	If they have/until the end of line --no, happens all of the time, I should show.
	-- my Java program class foo, blah-blah-blah, this functions does stuff, -- whatever -- up here we have fields, string A, B, whatever -- and then have closed curly brackets, I want to make sure this is fine.  I go ahead, from here down to here -- I've, why I actually to fail to comment anything more when I type that from Java.  In fact it's now not compiled.
	Says I have comment, slash star, keep going until I see a star slash, here is one, and comment ends there, I avoid, failed to comment that out and line 10, I have a syntax error, you can't have a closed comment without having opened it, oh,  I want these comment to nest.  It's sow natural, I want these to nest and they don't, and in C++ and C sharp and Java script, they just don't nest, I'm sorry, you want toe use block comment and uses/on every single line for 500 lines, yeah.
	-- I have to say, why not let them nest in Racket, there's a block comment and sure enough they nest.  So I don't worry about that if I use them inside there or not.
	Okay.
	Where was I?  -- using the stepper.
	Close the test case stuff.
	I want to go through step with this.  And point is not building up a bunch of pending stack frames or bunch of pending calls and I want to realize why, why not building up spending stack frames when I wrote it, I wrote the same function but wrote it   differently, some sense this is not doing anything with the machine code or smart compiler, just substituting check by check.  Check-expect of string append, lie, replace spring append with purple part, lambda, that was just that calls the helper.
	So, yeah I go ahead and call helper function, call in green part, call helper function with hi, bye aloha and whoa.
	If I think about it, it's the value of strs and results so far in my Java program.  In fact, that exact same trace we did before, we're going to see that happening here.
	So, okay.  We step, we, okay go ahead and saw 2 help, this lambda expression we step through it a bit.  Substituting in a list, is that list empty?  No.  That's going to be false.  Take out that false, I'm sorry to scroll a little bit there.
	-- get rid of that, con where the first branch is true so the that true branch.  String append first blah-blah-blah, which, oops go back -- little confusing, I wish they simplified rest here, bye aloha, is next iteration of strs, and string append here is the, here we are.  There we are.
	We see the my value for, no still night quite simplified, little bit more, as substitutes in.
	Okay.
	Here we have the list of bye and aloha.
	And the next step.
	Next step does string append.  And this is the next step in that walk through.  List of list of bye aloha and whoa and call that function, step through more.  Da-da-da da --and we now have, list of aloha with, string of pend, list of aloha with the string bye hi whoa, this is third iteration for the loop.  Notice what we don't have here, call one function, we don't have a bunch of pending function calls waiting around for something else to be answered before we can figure out the answer.
	We can say this function is tail recursive, step through the loop, to the if statements -- and we get through and now have empty list along with the string aloha, bye, hi, whoa and last time we go up through the loop again, we go up to the stop of the function cond and ask, is the list empty, str empty, sure enough it is, return the result so far -- which is exactly what we.  Expect and check-expect passes.
	-- that's the end of it, so -- what's the gist.  We went through and didn't build up a bunch of pending calls.
	Looking at code that does this.  Why not build up a bun much of pending calls?  We call this tail recursive, saw 2 help, made recursive call here and result of recursive call is what the top level function wanted to return as well.  That makes tail recursive, how does that make it different, go back and look the first version, here is recursive call, -- but the answer to recursive call is not the answer to the top level function, right?  
	The answer to that recursive call, needs to, still did some more work, we need to append something on to the front of that string.  And that's why we had.  In fact, it was this string append that was sort of had to wait around, waiting for the recursive call to finish, and recursive copy had toe wait for that to finish, that's why we build up stack frames.  which of these functions process the entire list but one building up spend pending stack frames, because string append has to wait for the entire thing to return and then has to do more work.
	Okay?  In the tail recursive version, yeah, recursive call, whatever that returns is going to be our answer, you don't node need to do any more work, so you can go ahead and continue.  So -- okay.
	And that's why it is tail recursive, so we can go ahead and write that down here.
	A function is tail recursive if the recursive call is the last thing it needs to do.  Doesn't need to combine the results of or do any more work with that recursive result.
	So if language implements tail recursion -- so, should Kay -- if function are tail recursive or not, if good compiler can identify function as tail recursive and say, I know it looks like you're suppose to make recursive call, but don't allocate new stack frame, reuse it and have same parameters and redo those.  -- wait, we don't need to allocate a new stack frame.  Readily code is either tail recursive or not.  Whether or not compile letter recognizes code, it turns out to be scheme or Racket compiler, you are require toad recognize tail recursive code, and required to optimize it and not build up pending stack frames.
	Side note.  In Java, write functions, recursive functions in Java, if I write a function that's tail recursive in Java, the while err does not optimize that.  Okay.
	It turns out.  The Java compiler people are idiots they have a certain thing that, stack traces in the presence of exceptions have to, you know, be present.  So if there's a, exception thrown after 5 recursive steps you need to show the 5 things, those 5 stack frames.
	Okay.  For whatever reason.  So, (Inaudible) generate good optimal code even when the function is tail recursive.  Racket will, a lot of language will.  Let's do one more example and call it a day.
	Let me uncomment some of this.
	Yeah.  So just summing up numbers on the list, we already wrote this function, one of first list functions, we have return 0.  Otherwise find the sum of the of the rest of the list, is this function tail recursive, sum version one, is it tail recursive?  Why not.  Beside it's says in big comments it's not tail recursive.
	What was tail recursive, recursive call is last thing it needs to do.
	-- did, if tail recursive you call at end.
	Yeah.
	Why is this not tail recursive?  -- there's recursive call -- exactly, the plus, I can't, the answer to recursive, I get answer from recursive call back and I still need to do work.
	Evaluating this, I need to call plus, pending until recursive call comes back, so we build up stack frames where plus is the thing waiting to be done.  Exactly.
	Okay.
	So that's not tail recursive.  But wait a minute, that Java -- Java function, has to do the Java function with while loop.  Version 2, take in list of numbers, list of doubles I guess, I have sum so far, starts at 0.
	Oops.
	0.0.  I like writing 0.0 to remind myself it's a double.  To make sure it's super clear.
	While numbs is not empty -- go ahead and take sum so far and add first number onto it.  Okay.
	And then go ahead and take list of numbers and -- hey, take, everything but the one index 0.  Take all the rest of nums and sub list, this is optional argument here.
	Maybe I should leave that off, I don't know, 2 flavors of sub list, take one argument or 2.
	Pass an one it will take up to the end of list, which is what that does.  Anyway.
	Okay.  Go through that loop and, clearly no stack space built up here, while loop with no recursive calls.
	How are we going to go ahead and do this ourselves so here is what I'll do, I'll give you, say, write this Java, or write a Racket function in a tail recursive way.
	And I might ask you write the Java function first, while loop and get a 0 and sub list of one to simulate first and rest.
	And here is what you do.  This Java version had 2 variables going on.  Nums as well as sum so far.
	And assign to go both of these as program progresses.
	My code better have a nums and sub so far.
	Nums will be handed to me but sum so far needs to start at 0.  How do I make my version ever sum.  This is given nums I need 2 variables going on.  Sum so far and nums, sum so far I want initialized to 0.  My outer function is just a wrapper, helper goes ahead and has numbs and sum so far, which is 0 the first time through.
	Okay.
	That was sub -- we're going to go ahead and still do the cond.
	Empty of nums, and, cons of nums, and cons ever nums we say we have the first of nums to deal with, that's true and rest of nums to deal with.  And you know, just sitting around, remind me I'll say we have sum so far.
	Sitting around, and for this one we say, I don't want to make the recursive call and have to do more work so not put in recursive call now.  Like we've been doing up until 15 minutes ago.
	-- okay.
	So, now, I want to make this sum help, I want to make this as allows to as I can this code down here, I already have initialization, if done there, while is not empty, if is empty, return sum so far, we can do that.  If it is empty, return sum so far.
	-- wait, otherwise, what do we do?  Update sum so far, update nums and go backup to the top of loop.
	-- okay.  And top of loop is testing, for empty or not, that's making recursive call here -- call sum help, what is new value of sum so far -- it's sum so far plus the first.
	-- okay, my new value, call sum help first parameter is going to be -- plus -- copy and paste that -- that's my new sum so far.  What is new value of num, back to Java code, what was the new value of nums at the top of loop, it was the rest of nums -- 
	Okay.
	So I still have, those things are in template, I use them, didn't do recursive call on rest of nums and decided toe write it like this.
	And now, the sum help, corresponds directly to this while loop.  -- and I guess the return part.  But, it comes after it.
	Going up to the top of while loop means,  make recursive call, go to top of while loop but want different fall for so far, go backup here and have different value for sum so far, have a different new value I pass in for nums recursively.  Okay, that's -- kind of cool.  And again, is this tail recursive?  Yeah, here is recursive call, if this recursive call returns 17, the answer to the overall function is 17.  So -- okay.  So this is tail recursive and I'm going to finish with, thinking about the purpose statement.  Back when up here and wrote sum version 2.  This is pretty easy, return the sum of the all the numbers in the list.  Great.  That was a pretty simple purpose statement.  What is the purpose statement for sum help?  -- well, sum help was given a list of numbers -- could be pretty small and sum so far that could have been built big, what is the purpose the sum for help. 
	It returns the sum of all the numbers here plus whatever sum so far was.  In particular if I call sum help of 17 and list containing 2 and 3, the answer is going   22.  Should be 22.  I have check expect for that.  Sum help of 17 and the list with 3, 2, suppose to return the sum of all the numbers on the list plus whatever sum so far had been, sure enough it does.  It's interesting when I have to sit down, I don't usually, it's weird to try and come up with the purpose statement of sum help that mentions both of its parameters and what's going to return given both of those parameters.  But you know, it turns out, -- if you ever go into code and trying to verify code and automate set up conditions true that is in loop, loop variance, so you can prove properties about program and prove it correct, you try to name the loop in vary anti, the loop in variant is the purpose statement we do up in tail recursive helper verse.
	ha purpose statement is -- what, basically what the loop in variance is.  I know I have -- variables that are changing -- like in Java world these variables change overtime, I know some so far, and nums is changing, what stays the same is sum of the numbers inside that list plus sum so far.  That total, I claim is always the same.  I can prove it's the same by proofing it holds each time through the loop.  Recursive loop for mathematical deduction, the number of times.
	Okay  .
	That's side note.  What I don't want you to be able to do is see and understand why, the Java while loop, how we, manage to contrive to turn that into a recursive function, so now, Racket doesn't have a while loop.  There is no while loop built into Racket.  We don't really need it, rack ka tears are, if I need while loop I'll write this here, and writing the same amount, now there's almost exact one-to-one correspond den between Racket and Java code, the only difference is where you put parens.
	The while loop doesn't save me much typing even.
	I can have unit test for some help now, that involve not being 0.  Java code with unit test I have no way of getting to, 5 I want (inaudible) to that loop without using debugger, conditional breakpoints and doing a lot of work by hand.
	So this I think it kind of cool.  If you have a loop you don't need a loop in the language you can use recursion and it's going to be not even pending and building up stack frames.
	Yeah, while loops and 4 loops are essentially the same thing.
	In fact, make a 4 loop and rewrite as while loop and do exactly what was done here.
	-- 4 loop is a while loop where you have some of conditions and things at end of loop moved around a wit bit it makes you wonder why while loops and 4 loops, why does Java include both, I'll leave that as thinking problem for you.  It's more convenient, what, makes more convenient, besides to say it's shorter.
	I think there's a tangible it does for you besides organizing the code.  They both have their place, while and 4.
	-- okay.
	Da-da-da.
	I want to spend the last 6 minutes here, won't talk about this, won't worry about it.  But point out now that we say, I can write, recursive function that does the work that a while loop would do, I claim I can go ahead and write my own function, so even though there's no while loop built into Racket, I can go ahead and make my own -- while loop.  So here is an example of if I had a while loop I wrote myself and I wrote down here in this file, I can do that.  I'll call it while slash list, here the idea of while slash list, give where to start, give conditions, should I keep continuing and how to update my starting point, my variable, and I'm going to return a list of my index variable overtime through the loop.
	Every time through the loop.
	That's my while loop.  Here while loops always return and answer.
	Give me the starting index, and okay -- and give me the while conditions.  So give me the number N line 7, while I'm positive go ahead and subtract one.  And it will become 6, positive subtract one, it becomes, 5, 4, 3, 2, 1, and keep doing while it's positive and when no longer positive, my answer is going to be the value of that index variable at the start of each loop.  I don't have to do this.  This is just how I wrote it.  But okay.  Yeah, list, so nums down, here, I'll name it nums down, I can write it literally, while list, start with N 7, while positive subtract one, put into answer and subtract one and continue.  Put in answer, subtract one and continue.  Here index is list A, B, C, here is list, while it is a constructive list, throw that into my answer, and -- take the rest of it an loop back.
	-- and the answer, list A, B, C, construction list, yeah, put that in as first part of answer, take the rest and continue, list BC, is that a cons, yes, it is corrective list, throw in answer, and take the rest of it, is that cons, yes, cons C empty.
	Throw in answer, when I reach empty list, this condition fails and I'm done.  Here is while list that does that.  How does it work?  Go ahead and Kyle while list help.  By the way I'm going to have index, my condition to continue, that's going to be a function, that's why I'm mentioning this here, ties in with high order function.
	What do I do when I call while list, I passed in function, one of 3 things I passed in.
	Here is function positive, takes in index and says yes or no.
	So -- yeah, -- and I say what to do with that index to update it, how do I update index.    okay.  I'll give you index, I'll give you a function, should I continue, and give another function how to update it, oh, yeah, rest was function, sub was function, takes in index and returns new index, would you passing functions is cool, I don't know if you noticed.
	We'll go ahead and while list index update.  This while slash list is loop that keeps list of answers, starts out empty.
	Here is helper function, index, whether or not to continue, update rule, again these 2 are code, and then my result so far.
	 Start -- strs is empty list and add on every time through.  What does the code do.  Takes index and calls continue function.
	I have index, 7, should I continue, is it positive?  If so -- go ahead and loop, okay, with what my updated index.  That's sub one of 7, back on this, example here.
	Apply, and apply sub one to it, loop with updated index.  The same check for whether I should continue positive, same update rules subtract one, and results so far, add, index on to the front much result so far.
	And then keep going back and doing this over and over again.
	Okay.  Index of 6, well positive, positive, of 6, okay, go ahead and return, WL help of sub of 6, that's 5, same continue, update, positive, sub one and can   this, cons 6 on to, my list of just had 7 before.  So I have list of 6, 7, and so on.
	When I find, this finally is not true, else clause takes over and return results so far.
	And turns out if you pay close attention, I was building up these answers in reverse, building up answers with 7 -- I'll reverse that list.
	Reverse, you can write that function yourself, if you don't know how, go ahead and write it using design recipe, -- and, so that's while list, here is another example of while list.  I'm going to start with index 10, here is condition, should I continue?  Hey.
	Is my number less than 50, this is lambda expression, give me number and I'll tell you if less than 50.  Continue as long as less than 50.  Here is update rule, take number N around add 7 to it.  What does it return?  -- copy, -- that right there.  I started at 10 and add 7, and keep adding 7, while less than 50 and then I stop.
	So -- that's what this function returned, while list, so here is the cool thing, imagine you had language that didn't have while statement built in, you can write it yourself.  And if function has things like, anonymous functions, yeah, it's flexible thing, you pass in, you make the while loop a function and pass in the stopping condition and end of loop update condition.  You pass those in as chunks of code, whether they're functions you make with lambda or functions you pass in here or here.
	So that's the really cool thing, to finish the lecture with.
	-- okay.
	Is this -- is this code, ask -- does this code follow the design recipe?  -- does it follow the data definition for a list of   items.  Remember that, we have a list of items?  Wait a minute we don't really have a list, we're not given a list.  Like this thing here, doesn't really follow the tom split for list of items because it doesn't take in list of items much must take in numbers or functions.  These numbers, not like natural numbers where we countdown like example before, can I go ahead and write infinite loop, --I'll start at 10, keep going while I'm positive, and add one.
	So 10, and then 11, 12, 13, and keep going as long as that is positive.  I'll end you on infinite loop, I can now write infinite loop here, okay.  So program ran out of memory.  Okay.
	I can increase the memory and so on.  But -- why is it out of memory, not because of stack, because I'm making a list -- and keep adding more on to that list and that list has used all memory I had.
	Okay.
	-- so, one thing to note, when you stray from the design recipe, you now have the potential for, infinite loops, if you follow design recipe correctly, it will be impossible to write infinite loop.  Why?  Because you're following data definition, data definition is well founds, or any piece of data, and you only work on taking that datum and some parts of it, that's side push -- note that.  Hey we're varying from the template here, in fact these tail recursive function are not what the tom split is giving us exactly.
	-- but -- we understand while loop is better now, maybe.
	You don't need them built into your language, you can write them as functions yourself.
	If you really needed to.  So -- okay.
	I'll go ahead, and -- leave you with that.
	I think there's other, one other, what is this?  I'm not sure what this is.
	Here is while, using while list and -- doing something and what does it return?  -- oh, returns a list of, square bullseyes.
	Here is index variable was not a number, it was not (inaudible), it was an image.
	So I started with empty image and how do I update every time through, I did an over, and this is end of loop update, overlay image with something else, overlay image I'm given with on top of a square, okay.
	I'll leave you with that.
	We have are now -- we have conquered while loops, we understand them in a way we did not before.  Okay.
	Once D2L is stabilized put it on there, your homework, next homework I'll have tomorrow as well.
	Next process list, list of bullets.
	Okay.
	Okay.
	All good?  -- I just realized, cable unplugged a bit again.
	Basically a week -- it will be a few functions and try to get out tomorrow and have to due Monday, get out tomorrow morning.
	-- I'm, basically we're behind, these are functions on lists that we talked about 2 weeks ago, so 2 weeks behind the lecture on homework.
	-- okay.
	Sounds good.  -- I'll, see you all, we will have an exam in a bit, but not for 2 more weeks at least.
	This is definitely a 3 credit hour passes, it takes 2 to 3 hours outside of class, this is like 10 hours outside of class, or 9 hours plus 3 for class, at least 12 hours a week.  I think the distance format is hard to absorb in 3 hours at once, you have to go back and watch that stuff and it takes more time.
	 -- you're telling me about that, yeah.
	-- hopefully I'm going to guess that the -- time spent, I know a bunch of people spent time on the grammar questions and some sense that was maybe the time that, I hope would have been spent between every lecture and the next, reviewing notes and working through examples.
	I think people didn't do that, hit the homework and had to go back and figure things out from scratch again, not scratch, but -- doing the work that hopefully could have been intersperses, but yeah, it's tough class and the term is tough, takes a lot of time regardless and distance format is just -- tough format.  So -- if you did well on this homework, it was a lot of work but hopefully that shows you're getting the ideas and you can put them altogether.
	Okay.  Any other questions?  -- if not I'll see you next week.
	I'll put the recordings up right now.