So we're live, says this, graphing exponential and log function. We're going to start out looking at a couple of exponential functions. It says, consider the following function, y equals 2 to the x plus 2 minus 3. I'm going to argue that this is an exponential function. Amanda, how do I know this is an exponential function? Where is the x sitting? What's your base here? I'm going to argue this graph is based on this. And to graph either a log function or an exponential function, I'm always going to start out by doing a table of values for the basic graph. Then I'm going to do the transformations, then I'm going to sketch it. In other words, I'm going to plug in a zero right there. When x is zero, what's y? What's 2 to the zero power? What's 2 to the zero power? One, I know that when x is zero, y is one, that's on the original. I'm not going to put this on my graph paper because it's been moved around. Put a 1 there. What's 2 to the 1? 2? Put a 2 there. What's 2 to the 2? Put a 3 there. What's 2 to the 3rd? 8? In your head, put a 4 there. What's 2 to the 4th? 16, which is probably off my graph, which is why I didn't bother actually trying it. I usually try 0, 1, 2, 3, and I try negative 1. What's 2 to the negative 1? Elevator. Okay. And then there's one more thing. Kirsten, what does every single exponential graph look like? What I want you to realize, Kirsten, is your lower hand is curving closer and closer and closer and closer and closer to zero, but Kirsten, it's never touching zero. What I want you to realize is there's an asymptote. And what's the asymptote for an exponential starting out? It's the y-axis. Sorry. I said it wrong. Fixed that on the internet, Mr. It's the x-axis. This is the asymptote, which as an equation is this. Every single exponential graph has that. And then if there was a 3-dare, these numbers would be different, but the shape would be similar. Okay. I'm going to add two more things just for practice. Underneath where it says asymptote, I'm going to write domain and I'm going to write range. If every single exponential graph looks like this, what's the domain worth memorizing? What was the range of every single exponential? They were everything above, but not touching zero. I would, now it took us about three minutes to do this in your head quietly. It takes about 30 seconds when you get the hang of this. You jot this off in the margin somewhere. Now I wrote here, do the transformations. How has this graph been moved? What does that plus two do to the graph? What else? I think three down. Yes, because the three is no longer on the y's, so it's not backwards. Good review of transformations. Yes, see it? So, you ready? When I say left, what I really think is x values, x values, x values, I would take out a pencil or I'll change colors and I would say, move that to left. Move that to, by the way, to left is the same as subtracting two on a graph. Yes? Move this to left, move this to left, move this to left. Is that okay so far, Katie? What letters right here? Because I asked you to, what letters right here? I'll never get tired of that. A y, so I'm not going to touch that because I'm doing left and horizontal. What letters right here? X, so the domain would move to left, sorry, to left for you guys is this way, does that really change the domain? If you go from negative infinity to positive infinity and just move it a bit, okay, so that's not going to change, but I would look at it just to remind myself. And Katie, what letters right here? Because I'm not going to change it then. Now, down, vertical, I'm going to change anything with a y. Three down means subtract three. This is going to become a negative two, a negative one, a one, a five, one and a half, take away three, Kirsten is negative 2.5, okay, I can do a decimal. Kirsten, what letter is right here? Because I asked you, I'm never going to get tired of that joke. Since it's a y and we're doing a vertical transformation, I'll also subtract three from there, what letter is right here? I'm not going to touch that because I'm doing vertical stuff. What letter is right here? So I'll subtract three from there too. In fact, I can find the new range fairly easily. The new range is going to be everything above negative three. So if it was multiple choice and I just asked you, what's the new range? Do you now have a way you could get that without graphing? Okay, now let's graph this. I always graph the asymptote first. The asymptote is not y equals zero. The asymptote is y equals negative three. That's a horizontal line, negative three, high, so far so good. And then it looks like this graph is going to go through negative two, negative two, negative two, negative two right there. Negative one, negative one, zero comma one, one comma one, two, three, four, five. And also negative three, negative two and a half. I'm going to argue those five points if we remember what Kirsten's arms were doing are enough to figure out the rest because what does every single exponential graph look like? Or I'm pretty sure this way, by the way, that's why I had you doing that. It's so that, in fact, I would even argue this. Kirsten, if all I could find were those three, I think if I know it's an exponential and I know it's supposed to look like this, I think I could say, oh, it's going to go like that. Five is nicer to have, no denying. And let's bring that point back, there we go. So it's going to look like this, that's how I would graph this exponential graph. What if there had been a negative in front that would also give me a vertical reflection that would flip that, change the sign, change the sign, change the sign, change the sign, change the sign, ignore that and instead of greater than, you know what it would become? Below, less than, that'd be a vertical reflection. Example two we're going to come back to, turn the page, example three. I'm going to argue that this is an exponential graph. You know how I can tell just by glancing at it? Yeah, I got it. What's this graph based on? Well, I gave you a hint, Holly, pause. What don't you like about this one? What's bugging you about this one? Why is this one looking tougher than the first one? Fraction base, it's not a fraction base, yes it is. Steph, I'm telling you it's not a fraction base. Mr. Dewick, I'm telling you I see a one-third there. Steph, I'm telling you I actually see this, what did I do? Elevator and now it's no longer fractional. I said, look, if there's a fraction, that's just like having a negative in front of your external. This graph is based on y equals three to the x. I did tell you to memorize certain exponents, this is why. Because if I put a zero there, what's three to the zero? One, what's three to the one? Three, what's three squared? Nine, what's three to the third? I doubt I'm fitting that on my graph. So I'll write it down anticipating I won't use that. Oh, what's three to the negative ones, Steph? Three to the negative one, I agree. Oh, what does every single exponential graph look like? It has as an asymptote, that there. And then just for practice, we're going to add the domain and we're going to add the range. So the domain for every exponential we said was all reals. The range for every, we said was everything above zero. Now let's list our transformations. What's going on here? Oh, correct order, please. Expansion compressions, do you see any? Where? Ah, way up here. There is a coefficient in front of the x. Horizontal or vertical and how do I know? Because it's an x and timesing by two, is that a horizontal expansion by two or a compression by a half? So over here I'm going to write horizontal comp. A half. Why over here? Because there's room, you don't have room to do it over here. Like I did in the previous one. Are there any other expansion compressions? No, now if there was a coefficient in front here, I can handle it. Be a vertical stretch. Big whoop. What did we do after expansion compressions? Remember reflections? Are there any? Ah, yes. Now there wasn't in the original, but I introduced one by rewriting it a nicer way. Horizontal, how do I know it's a horizontal reflection? Because where is the negative next to the x? Any other reflections? No, slides. To what? Now remember Cassandra, anything with horizontal only affects stuff with an x in it. Anything with vertical only affects stuff with a y in it. So now I'm going to fix my points. Horizontal compression by a half, that's the same as timesing by a half, or holly dividing by two, what's zero divided by two stays the same. That's going to become a one half. Yeah, decimal, I'll deal with it though. That's going to become a one. That's going to become a 1.5. That's going to become a negative one half. Raggedy, what letter is right here? Oh, not going to touch that. What letter is right here? Now if your domain is all reals from negative infinity to positive infinity, and you do this, what's your domain still? I think it's still all reals, even if you've compressed, so that's not going to change. Oh, and what letter is here, Raggedy? It's not going to touch it. Check. Horizontal reflection, anything with an x is going to become negative. What's negative zero? Oh, zero. Negative, negative, negative. Oh, this one's going to become positive. And the range isn't going to change because they take your range and you flip it. I'm pretty sure that still ends up with negative infinity, positive infinity, yes. Verticals, two up, three, five, eleven, maybe off my graph, but I can eyeball it. Yeah, you know what? This 27 is not going to fit on my graph because 29, I'm not going to bother. Ooh, two up, this is going to be two and a third, which I can eyeball. Roughly, what letter right here, what letter is that? That's going to get moved two up, what letter is that? That's going to get moved two up, is that okay? Will I always graph first? Yes, until, oh, two up, Mr. Dewick. And then this graph goes through zero comma three. Negative a half comma one, two, three, four, five. Negative one comma eleven, which is one off my graph, but I'm going to argue those three points. Christian, what does every single exponential graph look like? Or, and I think it's that second one, starting bigger, getting smaller. Can you see it just from those three points? I'm positive it's going to go like this and it's going to get closer and closer to that asymptote without touching. Okay, oh, how could we check our answer? Get your graphing calculators out. Clear any graphs you have in there? Clear, clear, clear. I'm going to type in this equation, the original. Now I've got to type very carefully. First of all, I'm going to have to put the one third in brackets to the power of, and since there's more than one thing in the exponent, I'm going to have to put the whole exponent in brackets, bracket two x closed bracket, plus two, enter. My graph paper I think goes from 10 to 10 and 10 to negative 10, yes, which is zoom standard, which is why I try and use that when I'm typing, so I'm just going to make sure, I'm going to go zoom standard.  We can be even more specific. So once you get that graph to appear, press the trace button. This is what allowed us to move around on the graph, but it also allowed us to enter, oh, first of all, mine started right at zero three, which I had on my graph. What's another point I had on my graph? What went with the five? What went with the five? Oh, you know what? I'm going to type in negative one half, and I'm going to see if that goes with the five. Does it? I have to be right. I'll check one more just because I'll check the negative one, and it goes with an 11. So you can use the trace button to type in values to see if you're correct, except on the test you won't be able to, but in your homework, because I don't have an answer key made up for this one. This is kind of how you'll check your answers. Is that all right? Yeah. Did you press your trace button? Press graph. Give me one second. I'll come over there and pause. Let's go back to example two, log graphs. Example two, Katie, what's the base of this log? Two. What that means is this is the inverse of this. Yes? Okay. I know that this graph goes through zero, one, one, two, two, four, three, eight, four, 60, I'll do my powers of two. Oh, and I'll even add one more, one, sorry, not one half, Mr. Deweyck, negative one comma one half. I deliberately didn't put those in here. I jotted these off in the margin. I know my exponents. How do I find an inverse? I'm going to argue the key points for a log base two are one half negative one, one, zero, two, one, four, two, eight, three. How did I get those Trevor? I literally switched the X's and Y's around. Oh, did I do a big rant on inverses last unit? Oh, what would the asymptote of this guy be? What was the asymptote of every single exponential graph? What are we right at the bottom of the previous question there? Here, yes? No, your answer was correct. I mean, if the asymptote for the exponential is Y equals, the asymptote for the log should be X equals, going to switch the X and Y around. Oh, I'm even going to go further. Won't it be all reels for Y and X greater than zero for domain? Switching the X's and Y's are.  I figure if you know this, you can derive the log one in 30 seconds of thinking. You can, by the way, feel free to memorize it, Jessica. If you want to memorize the logs inside, no, go ahead. Every year I have some kids that do that. I usually just, it's an inverse. And, oh, did I have you write out all your exponents on a page and we know our exponents? Now, let's do the transformations. What's going on here? Expansions, compressions, reflections, slides? What's that mean? Four what? What's this mean? One what? Now, again, when I think left, I think X's, X's, X's, Oop, X there, Oop, X there. When I think down, I think Y's, Y's, Y's, Y's. Four left means take this number and minus four from it. That'll be negative 3.5. Yeah, it's a decimal.  Negative three, negative two, zero, and four. Oh, look, look, look, look, look. Asymptote, not X equals zero, X equals negative four, four left, yes? Range, oh, look, look, look, look, look. Not X bigger than zero, X bigger than negative four, yes? Oh, oh, that's a Y. One down, negative two, negative one, zero, one, two. Oh, and the range is all reels vertically. If I move all reels one down, I think I'm still all reels. What will this look like? What did I always grab first as my guide railing? And that's now X equals negative four. That's a vertical line way over here at negative four. And then it's going to go through negative 3.5, negative two, negative three, negative one. Well, that scared me. Negative two, zero, zero, one, four, two. Can you figure out what this graph must look like? I think it does. Now I'm going to need to fix my asymptote just a little bit there. I think it does this. I think it shoots nearly vertically down forever and ever and ever and ever. And it shoots to the right. And if you think along and hard, Kirsten, if you were to reflect yourself about the line Y equals X, that is what you would look like when you did that. Ooh, should we check? Let's see if we're right. Mr. Dick, how the heck do I graph log base two? Base change log. Log of X plus four, closed bracket, divided by log two. Isn't that how we did base two on our calculator? Minus one. That's how I would type that in. Put what's inside the log and brackets and divide by the base. Or you could have, if you really wanted to be scary, K, could have used LN and LN. That would work too, but I usually use log base two. Pick graph, what do you get? And you know what? You don't quite get our graph. Now, who has a TI-84? You do? Your graph might look a bit different because the software was improved. Does yours start in midair over here too? Oh, yours does? You see, we're there? Yes. The graphing calculators have a heck of a time with that nearly vertical line. It does not know what to do there. I guarantee this is wrong. The graph does not start out of nowhere. It has a range of all reels. It continues going on down there, but your graphing calculator can't handle it. Let's check a couple of our points. Shannon will press the trace button very firmly. Well, how about negative three? Negative three goes with negative one? Check. How about negative two? Negative two goes with zero? Check. I'm pretty sure I'm right. Let's do another one. Example four. Yep. Yep. This is about as tricky as I'll throw at you probably. Graph that. Well, this graph is the inverse of that. Steph, what do you like about that one there? Okay, you know what? It's really the inverse of that, which is this with a horizontal reflection. Is that okay? So in my mind, over here in the margin, I'm going to do this. Let's see. If I put a zero in, I'll get a one. If I put a one in, I'll get a four. If I put a two in, I'll get a 16. You know what? I'm not going past that. In fact, I doubt that 16 is even going to fit my navy. Oh, and I always try negative one. Negative one, what's the four to the negative one is going to be Katie? That's that. However, that's not what we started with. Steph, we started with one quarter to the X or a negative, oh, you know what? Positive, negative, negative. See how I got that? What are my key points? Now switch your X's and Y's around. One quarter goes with one. One goes with zero. Four goes with negative one. Sixteen goes with negative two. Oh, asymptote, X equals zero. Yes? Oh, domain, range, domain X greater than zero, range Y all reels. Oh, then it says do the transformations. Now let's go back to our original here. Expansions, compressions, are there any? Yep, vertical or horizontal? If it was horizontal, where would it be? Isn't that next to the X? Vertical and it's not backwards. This is a vert expansion by two. Any other expansions?  Reflections, is there a negative there? Is there a negative there? We had one in our invert, we did that. We're coming back to this guy now. Slides, one, one what? So vertical means Y's expand by two. Two, what's zero times two, still zero. Negative two, negative four.  Oh, and this would expand by two because that's vertical because it's got a Y in front of it, Holly. But when you expand this, it's not all reels. Slides, one left. One quarter, take away one, negative three quarters. That'll be a bit tricky, but maybe. Oh, but this one I can do zero. This one I can do three. This one, 15. I don't think that's going to fit on my graph. Oh, but this is an X here as well. This is an X here as well. This is an X here as well. This is going to move left as well. Negative one. Oh, and the domain is going to become everything greater than negative one. Graph this, what did I graph first? And then it's going to go through. You know, I'll save this fraction one for last if I need it. It definitely goes through zero, zero and three negative two. Okay, and negative three quarters, positive two. Oh, you know, the only Kirsten shape that fits here, I think, is this. It's the only way I can get it to work, and we're right. Do you want to check? Well, really quickly I would go, okay, clear whatever I have here. Two, log of X plus one, close bracket, divided by log of a quarter. There's how I would type that in. It looks kind of like what I got. Trace negative three quarters. Yay, it goes through two, zero. Yay, it goes through zero, three. Yay, it goes through negative two. I am right. Take a look at the second sheet that I gave you, this one here. I'm going to give you about four of each, four logs and four exponentials to try. This part here is actually a lesson. So if you want to turn to where it says examples, does number two fit nicely? Let me see, three times two to the power of two bracket X minus one, close bracket, close bracket minus five. Yeah, okay, try number two, then skip, skip, skip, skip, skip. Oh, heck, you know what, nuke number two, go where it says practice questions. Find this page right here. I think you can try number one. That's tougher than I'll probably ask question two. So one, two, three and four and then practice questions one, two, three and four. I'm looking at this now and I'm not liking the way some of those graphs will look. They won't fit very well, but that's okay.


How's everybody done today? Three days of Closure Conj? We've seen a lot of really cool modern systems to handle new big problems facing the internet. And what I have for you today is some really old computer science. We have the problems of the 1970s. So this work, somebody wanted me to share the history of this work. This actually came out of Closure Conj last year when Dan Friedman and Will Bird came for the first time. And Dan was having a conversation with Rich about closure as a language, because he didn't know anything about it. I still don't think he knows anything about it today. But he was asking about different features of the language and asked if it had tail call optimization and said, Rich said, no, it doesn't have it. And it's not really possible because of the JVM. And Dan said, I think there is a way to do it. So he came back and he recruited me. And so that's what we're talking about today. And so just to give you a little outline, for some reason my clicker's not working in just a second. There we go. Okay, so here's a little outline of what we're gonna talk about today. We're gonna talk about the history of tail call optimization and the ideas behind constant space tail calls. We're gonna talk about the built-in tail call optimization support that Closure has, because it's got just a little bit. And then we'll talk about the system that I wrote, which I very, very creatively named Closure TCO. And I call it CTCL. And we're gonna spend the bulk of the time talking about the transformations that it does. And the three of them are listed there. Continuation passing style. Yes, we're gonna talk about CPS today. We've got thunkification and trampolining, which may be familiar to some of you. At the end, if we get some time, we're gonna talk about optimizations that I've been working on the last couple of weeks to make things a little faster, a little pepier, a little better. And then at the very end, we'll talk about work that I hope to do related to this and directly using this work. So I've got a couple of goals today. And I want you to be kind of in the same headspace. What I want you to know and what I don't care whether you retain after this. So I want you to have a high level understanding of what goes on in CTCL. How it does these transformations in order to enable tail call optimization in a language that doesn't have tail call optimization. I want, when somebody asks, how can you get tail call optimization out of Closure? It runs on the JVM, you don't have tail calls. I want you to be able to give two or three sentences about why the three transformations that CTCL does enables tail call optimization. And I don't think it's any secret to anybody who's talked to me at Conge very much that I think about continuations like constantly. I want everybody to think about continuations. I want you all to understand continuations. And I think that we've turned them into a monster that's really scary. And I hope to take the monster out of them today and hopefully give you a little bit more understanding of continuations if you don't already have a good one. I was gonna say, Dan's not gonna learn anything today. And I've got a couple of things. Oh, excuse me, sorry. So I also wanted to discuss how there are some benefits to using CTCL. Like I said, you can write tail recursive programs and they don't blow the stack like they normally do in Closure. But there's also some costs associated with the transformations that it's doing. And we'll kind of talk about those a little bit toward the end. Yes, as I was saying, there are also some un-goals that I have.  Things that we'll talk about or we might not talk about. But I don't want you to really think about these things. There's the internals of CTCO, the implementation. We're not even gonna look at it. I don't care if you understand the software engineering effort that went into it at all. We're not even gonna look at it. And the other thing, we're gonna see a fair amount of CPS today. Now I said I want you to understand a little bit about continuations. But I don't want you to be a CPS expert. You don't even have to understand the little bits of CPS that I'm gonna be showing off today. Okay, so we all on the same page. Everybody good? Everybody ready? Okay, so the first thing that I need to do, it's good the doors are closed. We're gonna imagine that this whole big room is a time machine. And we're going back to 1977. So unfortunately I brought you back to a time where everybody's using imperative languages. We got a lot of Fortran, we got a lot of PL-1, we got a lot of COBOL, but it's not all bad. We've got Lisp, although it's for academics, and nobody would ever build any big web-facing, database-backed program in Lisp. That's just crazy. But that's not the real problem. The real issue we have right now is a big debate. We have the debate between structured programming, which you and I and everybody in the room thinks of as the right way to program. It's using procedures and function calls and abstraction, proper abstraction in your code. But the alternative that everybody thinks is better is go-to. So there is this horrible, horrible, awful rumor that go-to is inherently faster than procedure calls. That procedure calls are stupidly slow, and yeah, sure, if I write my code using abstraction and function calls and everything, it's more modular, it's more readable, but my manager would kill me if I wrote a slow program with procedures and procedure calls instead of go-to. Well, it's also a good thing that we came back to 1977 because Guy Steele at MIT has just published Debunking the Expensive Procedure Call Myth or Procedure Call Implementations Considered Harmful or Lambda the Ultimate Go-To. He's truly a man after my own heart in terms of ridiculous names for things. And the main point of this whole paper was compiler writers, you're making procedure calls slow, and it's your own fault.  You're saving a whole bunch of values whenever you do a procedure call that you don't have to, and they can be a lot faster. And so kind of the keystone of his whole argument is talking about tail calls, and this is very prevalent, very relevant to what we're talking about today. So he gives this little example and everybody can see this, right? So it's this little Lisp example. He's defining a function bar that takes two values, X and Y, and it does a call to G with X and a call to H with Y, and assumedly, these are defined somewhere else. And then finally, notice I say finally, you make a call to F with the results of those values. So if you have any sort of background in computer architecture, then you're familiar with the idea of a stack. And if you're not, a stack is essentially the place where we save values for the current procedure that we're running. So we have our little stack off to the right here. And we come into a call for bar, and we've got X and Y, and we're gonna use this little space, and we get into the body of the procedure, and we see that we need to make a call to G to get the value out of it. Okay, so we're gonna save our stack frame, we're gonna call it a frame, we save our information, and we make G work above us. G's up there, he's gonna do his thing, he's calculating a value, it's all cool. He gets done, and we've got a value for him. And we can erase his stack frame and everything. We come back down, we're back in our original stack frame. Oh wait, but we still have H to work on. Okay, so H goes up there and he spins around, he does his little computation thing, comes back. We've got a value. And now this is the key point. We had values that we had to save when we were executing G and H, because we had to come back to bar, we had some work to do in bar, but now all we have to do is make the call to F. So if we were silly, we would say, okay, F, go do your thing up above me in a new stack frame. But what do we have to do once we get back from the call to F? What does bar have to do when we get back from F? Think about it for just a second. Nothing, there's no work to be done. Why are we saving information about bar? So, let's do just that. Let's just reuse the stack frame and put F in there. Let F work in there, and then we don't have to do the stack manipulations. All of a sudden, we see we don't need a new stack frame, we don't need to do the manipulations, and all we've done is set up for some arguments to go to the next function and we jump. It's just a go to. Not only do procedure calls not have to be slower than go to, they can be go to. This is a really just awesome idea. And luckily it seems like most of the compiler writing community, at least for the most part with procedure calls, got the message, and procedure calls aren't painful anymore. And so we learned, tail calls are super awesome. There are an efficient and natural way in languages that include constant space tail calls to do iteration. You can do recursion on lists and all sorts of fun things. If you've ever written a finite state machine or a parser, you know that writing it in terms of natural recursion is awesome. And it's so great that Guy Steele, who was also working on the scheme programming language and Jerry Sussman at MIT, they put it into the scheme standard. You're not a proper scheme implementation unless you have constant space tail calls. And the standard ML guys came along a little bit later and they were like, hey, that's a good idea. Let's do that too. So we're still in 1977. Looks great for the future. Everybody ever is gonna have constant space tail calls, right? Everybody in the room, 1977. Everybody in the future is gonna have constant space tail calls, right? Awesome, wait. Not every language ever uses constant space tail calls. And there are a whole bunch of them, but what we care about today is that the Java security model makes it so that we have to have a stack frame for every single procedure call. And therefore, our favorite little list implemented on the JVM doesn't have full constant space tail calls. Sad days. But it's not all hopeless. We do have a little tiny bit of built-in tail call optimization and closure. We have, you're probably familiar with the recur form. We can use this for self-recursion and function bodies or if you use the loop form, which if you squint and turn your head kind of looks like a while loop, there's a reason for that or so I've heard. It uses the underlying mechanisms for while loops to do that go-to with arguments that Guy Steele told us about way back when. And by the way, we are in 2012 again, so. It's sad times that we don't have tail call optimization everywhere, but we don't have to treat the room like a time machine anymore. In addition to the recur form, we also have this function built-in to close your core called trampoline. I've personally never used it. You have to do some funky little code transformations in order to get it to work. And actually, if you were paying attention to the very beginning of the talk, you would notice in the outline, we're gonna talk about trampolining as a transformation that CTCO does. And so we'll get into it later. It is important. It won't use the built-in trampoline. It actually rolls its own. But these are the things that we have to play with. So that brings us up to speed. We know about tail calls. We know about the story about tail calls and closure. And so now we can get to the system that I wrote called closure TCO. And the idea is that the way that closure stands now, if you want constant space tail calls, you have to roll it yourself. You have to know when to insert recur. You have to know when to do that funky trampoline transformation that we're gonna talk about later. And I'm a compiler hacker. And I like to write things that write code for people. So the whole idea behind CTCO is, you just write your code the way you want it. Let the compiler handle it for you. And of course, the main idea is that, like with the go-to with arguments, the compiler transformation will make that transformation as good or better than you could do it if you were an expert in how to do all these things by hand. So with that, we're ready to start talking about CTCO transformations, which you know means continuation passing style. So what in the world is a continuation? It's this weird abstract mathy thing. Why are we talking about it in terms of writing real software well? I hope to give you a real software explanation of what it is. But first, let's think about what a continuation does. You may not know this, it's fine. It's a thing that takes a value, it does some work and we'll think about it as some computation that's waiting to happen, and then it returns a value. If we were doing things in type closure, I was actually thinking about this with respect to Ambrose. This would be an arrow type, it'd be value arrow value. And you can think of it as a function. It's a very convenient way to represent them. In fact, that's how we're going to represent them in CTCO. And you can even think of the smallest continuation you can possibly construct. We call it the empty continuation. It's better known as the identity function. It takes a value, does no work, and then returns the value. Okay, so we've got a little bit of a picture of how continuations do their job. So now I want to make a really big claim. And it took me a really long time to figure this out and I think that this is the point that helps you think about continuations with respect to when real people, not mathy abstract people, write software. Continuations are stacks. It is just the stack. When we apply the CPS transformation to code in CTCO, what we're doing is we're taking that stack that the JVM handles for us. And sometimes we don't like the job that it does because it creates stack frames where we don't want stack frames. We take that stack and we turn it into a function. We've got it in our hot little hands. And so we don't care about the JVM stack anymore. We can clear it out however we want because all the information that was being recorded in that JVM stack is now recorded in this function that we have. That's super cool. So from now on and literally even in the middle of this talk, if you hear me say the word continuation you can yell stack at me. So I need some audience participation right now. When I say continuation, you say. Stack. When I say continuation. Stack. Continuation. Stack. All right. Okay. So in order to illustrate this point, you know, I'm just, at this point I've just said continuations are stacks. I love you guys. So let's take a look at an example of why my laptop is not changing. Okay. Apparently we've had a technology failure. You're gonna have to take my word for it or not. I have not tried turning it off and on again. Okay, well unfortunately it doesn't look like I'm gonna be able to show you part of my big claim. I was going to take the intuitive recursive version of factorial, which of course factorial is just, factorial of zero is one and factorial of n is n times factorial of n minus one, right? And I had a picture. I had this wonderful picture of the stack being built up where you see these big multiplications coming out. And you have to save this information on the JVM stack when you do it in the intuitive recursive fashion. And it blows up, it blows up in most systems because it's a non-tail call. It's like F, not like F, it's like G and H in our original example from the guy's steel paper. What you see from the example of CPSing it, and now you'll just have to come and ask me afterwards, bumming me out. But then I get to CPS for you, which I really like doing. You see that the stack that gets built up on the JVM becomes the actual continuation function that we're passing around. Like I said, we don't have to worry about the JVM stack. It's not holding values for us anymore. We've taken all those values and we've put them into our function and we use it directly. And the other illustration of how this is awesome is we take a tail recursive version of factorial and you get to see doing CPS on it how every iteration, it doesn't manipulate the continuation. It doesn't manipulate the stack. You guys missed a continuation. I just said continuation. I need two more. Okay. But the stack doesn't get manipulated. You see it's the same continuation flowing through the, thank you. It's the same K stack flowing through the program the whole time. And it shows the point that guy's steel was trying to make. When you make a tail call, you don't need to record information on the stack. You can reuse the stack frame. You can reuse the continuation. Awesome. Okay. So unfortunately, back to my slides. Okay. So now we've done the continuation passing style transformation on our code. Thank you. Stack passing style. I can't, I've committed now. So we have the stack in our program now. And we can clear out the JVM stack, like I said. So the next thing that we need to do is this thunkification transformation. And this was the weird little transformation I was talking about with the built-in trampoline function. And the idea behind thunkification is that every time we make a function call in our procedure, we wrap it in a function of no arguments, a fun of no arguments. Call that a thunk. It suspends computation. And the cool thing here is it breaks the computation into steps. And what I would love to show you if I could get a terminal running would be in the definition of factorial, you just wrap the tail recursive call in a thunk and then you can just run that computation one step at a time. And it goes until it completes and because factorial is a function that accepts the number five and returns 120, you see that that eventually happens. I'm actually, I'm gonna try this one more time. I'm not getting alt-tabbing though. Oh, hey. Hey! Here we go. Okay, so here we go. This was the point about factorial I was trying to make. We can take a step back now. So you can see we have our natural recursive version of factorial here. If you give it zero, it returns one. Otherwise it takes n times factorial of n minus one. And this is our call trace. This is kind of our stack. And like I said, you can see the stack kind of building up through the multiplications. And so if I had time, I would have shown you the CPS version in detail, but instead you can take a look at it. And you see that instead of building up the stack with a non-tail call, we have a tail call now and we're passing along this function that does the same thing as the non-tail call did before. And so you can see that weird thing that I said about continuations, that they perform the part of the computation that's waiting to happen. That's what's going on here. This multiplication with n is the computation that is waiting to happen. And so we've stuck it in a function and we have it in our hot little hands and we can run around with the stack now. And you can see that here. If you look at the call trace, look at that second argument to each call of factorial. It's getting bigger and bigger with bigger and bigger multiplications in the exact same way that the original stack got bigger and bigger and bigger. So you guys kind of believe me but right, we're using the closure data structure to hold the information that the JVM stack was holding for us before. So kind of get some nodding heads and yeah, we got a stack. Our continuation is a stack. And now hopefully I can show you this is the tail recursive version. It's an accumulator passing style which that's just a big fancy name. We don't need to worry about it. But it passes around the final value that we're going to return. And so there's no work here to be done when we finish the recursive call. So we should see here when we CPS it, we have this call trace where we've handed in the original empty continuation. Thank you. And it just gets passed along over and over and over again. We never change it because the stack never changes. So the continuation never changes. Okay, so this is the CPS transformation on the tail recursive version of factorial using accumulator passing style. And like I said, the next thing we need to do is thunkification. And so to do that, all we've done is put this little hash here. Now you know hash is a little reader macro that turns the thing into a function because we don't use any arguments and it's a function of no arguments. So now I should be able to show you this is exciting, now I can show you things. Oh, and one other thing to note here. I've left an entry point, this overload so that you can call factorial with the original number of arguments and it just sets up the empty continuation for you. So I can take this old function definition and I can paste it in here. And you can see when I call fact with five and one, well, what's this? We got a function back. Well, what if I invoke it? We got another function back. Well, let's invoke it some more times. Hey, we got a value out. So each one of those sets of parens that I just threw in there, that's us invoking one of those thunks that we did. Now, when you make a function call, you don't wanna wrap it in a whole bunch of parens. You don't wanna guess how many steps it's gonna take. That's annoying. So that brings us to our last transformation that we have to do in CTCO. Mac, you're killing me. So yes, wrapping a thunk, break the computation into steps. You just saw those steps. And this prevents the runaway stack growth because at each point where we were returning a thunk, we would have made a function call which would have made a new stack frame and if that continued, our stack would get huge and we'd overflow and things would be bad and we would be really unhappy. So this breaks it into the steps where instead of making that function call, we return a value. And that's the point where, you know how I said we could clear out that JVM stack? That's exactly where we do it. Which lets us move on to trampolining, which is where we do the running of that computation step by step. And in order to do it, we need to have some sort of looping construct in our language that has constant space. Well, you remember toward the beginning, I said we have at least one. We've got loop recur. So we're gonna use that.  And an important thing here is to figure out when we dismount this trampoline. Now there are a few ways to do it and I actually have to give Allen Dipert credit wherever he is in the room for coming up with a very clever way of doing it and I can show it to you now. Now that I have mastered my own computer. Okay, that's not what I wanted. There we go. So now we can look at trampolining and you can see that all we've done is we've taken our factorial function definition and we've bound it within the scope of this trampoline function. And the trampoline function is simply asking is there a piece of metadata attached to the thing that we were passed that says it's a thunk? Of course, we're not doing that right now. But now we are. And of course, when we make this entry point call here we need to load ourselves onto the trampoline. So I should, fingers crossed, be able to just grab this definition, copy, paste. I saw what it did there. Oh man, bumming me out. You're gonna have to believe me. So at this point we understand all of the different transformations that go on in CTCL. And just in summary, like I said, my major point that I wanted to make in this talk was so that you understood the transformations that are going on here. So somebody asks you, how do you get tail call optimization out of a language that doesn't have it? Well you tell them we CPS because that makes the stack an explicit thing that we have in our hands. It's a function. It's a continuation, which is a stack. Awesome. We thunkify our expression so that we can run it step by step and we keep the stack from getting too big. And then finally, we throw it on a trampoline so it does that run it bit by bit by bit by bit until it's done. Okay, cool. So actually at this point, although my manual trampoline failed because of copy paste errors, I can show you how CTCO does it directly. So you may have noticed I've loaded into a CTCO.core line or Apple. And we can just define our tail recursive factorial. That's the same definition we had before. Now actually before I do that, let's take a look at how this blows up. So we'd like to see how you're killing me. There we go. We'd like to see things break, right? So this is a normal called a factorial. Start the accumulator off at one. Oh, stack overflow. So let's go back to our original definition and let's just throw it through CTCO. And underneath it's doing all the CPS, the thuncification, the trampolining for you. Let's try that again. We got a big old number. Now one thing you may be thinking, well I could have done that with just using recurve because it's just calling back to itself. So a more interesting example to look at is these mutually recursive even and odd. So the idea here is zero is even and it's not odd. So we have these little functions that call each other asking, well if it's not zero, when we pass it to even, we subtract one and pass it off to odd and ask if it's odd. So if I, because I don't trust anything, I'm just gonna write it directly. And I think I still have time. Yes, I do want true there. Thank you, Dan. We have to change this to false because zero is not even and our recursive call is to even. Okay. Everybody think that's pretty reasonable definition for my even, my odd. We can ask my even of 12. This is gonna be really embarrassing if it doesn't work. Hey, 12 is true. If we say my odd, 12 is odd. Well let's say we crank this up a little bit. Uh-oh, stack overflow error. Let's go back to our definitions. Let's do it through CTCO. Let's do the same thing to my odd. Bad things would happen if I forgot to do it with my odd. Let's try that again. Bam. Okay. So now we're all good. We all understand the basics. We have CPS, we have thunkification, we have trampolining. We can tell people why it does that. But it's not all roses. There are some costs associated with this because of the code transformations that we're making. When we do CPS, we create continuations out of functions. And it takes some time to build new functions and we have to pass them around where we weren't passing arguments around before. We have all these thunks that we created. When we're running the computation step by step, the idea is we're doing it in a really tight loop. And we're just invoking, invoking, invoking, invoking. But that's still something that we didn't have to do in the original code. So it slows it down a little bit. Plus there's this idea of using stack versus heap memory. If you look real hard at the CPS transformation, you see that every single function definition, whether or not it's tail recursive or not, becomes tail recursive once you CPSed it. And so it looks like, oh, I just got tail calls for free. Well, no, you've traded the stack memory that you were using for your non-tail calls for heap memory because you use heap memory for your functions. And so eventually, instead of getting a stack overflow, you will get a heap overflow if your programs are written in a primarily non-tail recursive style. So that's why CTCO is intended for, I wrote something in a tail recursive manner and you understand tail recursive manner if you've read Dan Friedman's books, The Little Schemer and The Season Schemer and all that. And recursion is awesome and you use tail recursion. CTCO will be your friend. But if you've written a non-tail recursive program, it'll help you out a little bit, but it will eventually blow up. So some stuff that I've been working on, let's just go over these kind of quickly so we can possibly have some questions. In the last couple of weeks, I added an auto-recurify pass. So like I said with the version of tail recursive factorial that we looked at, you could achieve the same thing by just sticking a recur in there instead of doing the thunkification and trampolining. And so CTCO now just looks through and figures out, oh, you're just calling back to yourself, so I'll insert a recur instead. And I've seen a fair amount of speed up from that. It was also this problem that I had for a long time where you may have noticed that when I did my function definition, I overloaded it because when you do the CPS transformation, you go from whatever number of arguments you were passing around to that number plus one because of your continuation that you're passing around. And so you had this clash between the, when you were trying to call into the original version for say, so let's take a look at something really silly. The problem that we have here is that when we CPS the first arity, now we've suddenly got two bodies. One is trying to take a continuation in the second spot and the other one's trying to take an actual value. So the solution I came up with was inspired by Alan Dipert's trick of attaching metadata to all the thunks. So every continuation that's created in CTCO is tagged as a continuation. And so what you end up doing, I heard one stack, that's hilarious. So what you end up doing, and I won't go through the full transformation, you essentially ask, you ask is that second argument a continuation? And if so, you do the code for the CPS version of the body preceding it and otherwise you call into the original version. And it took me a little while to come up with this solution but I was pretty proud of it. And like I said, it was inspired by Alan Dipert. So I think that's most of the content that I have just finishing up, we have some future work that I wanna talk about. I focused on getting the correctness of this language. And so there are some glaring omissions and some of the expressions that it'll accept. So that's a small piece of work that I wanna get done soon. There's also some talk of getting this ported to closure script because people would like to be able to play with it there and there are some issues with the current implementation that only work on the JVM version of closure. I'm also signed up to write a tool CPS library because apparently people think I'm the CPS expert in the closure community. So that should be coming around sometime early next year. And finally I've got some other ideas for optimizations to try to make CTCO faster including coming up with a way to do minimal thunkification which I don't really wanna get into now if you wanna ask me about it afterward, that's fine. So the basis for a lot of this work was the first order one pass CPS algorithm by Olivier Donvy and I've heard reports that if you look at the CTCO code and you look at the paper side by side you kinda see how the CPS transformation falls out of it. And the other thing of course, I pulled most of this work from using parentheses to transform scheme programs to see or how to write interesting recursive programs in a stack based imperative inhospitable host which was written by Ron Garcia and a whole bunch of people including Dan Friedman and that was the reason why he was able to say to Rich last year. I think I know how to get constant space tail calls out of closure. So just a few thank yous too. Thank you to Dan Friedman for giving me all the ideas and all the foundations for this. Thanks to Alan Dipert for being the only contributor thus far on CTCO and inspiring some really interesting solutions in there. Thanks of course to David Nolan for helping shore up my obstinate schemer-ness into the closure realm. And thanks to all the Conj organizers for letting me infect your world with continuations. And what kind of compiler writer would I be if I didn't have a slide full of numbers at the end? Well I'm gonna go ahead and finish up. Thank you guys for listening.


Welcome to the Film My Runs Summit Club. We often call it the New Year Summit Club. This is the New Year's Eve Summit Club. We have in the past climbed Snowden twice and Scarfell Pike. Today we'd love to do Ben Nevis. Unfortunately it's a bit of a long journey for us to get all the way up to Ben Nevis on New Year's Eve. So here we are in the Lake District about to climb Helvellen. So I think that's the third highest mountain in England. I think so anyway. Helvellen is our is our goal today. It's not actually that far. It's about three kilometers to get to the top of of Helvellen from this car park. We're in Swirl car park on the edge of Thirlmere Lake in the Lake District. So three kilometers or so, 900 or so meters of elevation and then we'll be at the top of Helvellen. And me and Ellis are going to try and run up there. A little gentle jog to get us going. Right let's see what this sign says. Helvellen Stanna Sticks Pass. So this way across the bridge. Let's start off nice and gentle. We've got our poles. It's going to be very steep very quickly. It's not raining is all I can say. We're just over a kilometer in. We've climbed about 300 meters and you can see Thirlmere Lake down there. It's taken us 26 minutes so far. I'm going to get very foggy, very short. Okay we got about meters 800 meters from the top and it was really really blowing a gale. So we came back down so it will be even windier on the top. So let's see how far we can go. But I don't think we're going to make it to the top today to be the top priority and especially if we're taking kids with us. We're going to put them in any risk or we don't want them to feel so always best to be on the safe side. All right Alice you're glad to be making it down. How was that for you? Horrible? No it's not cold it's just really windy wasn't it? It's a lot wetter and colder now than when we started. But now that we're out of the wind it feels a bit nicer. Just too windy up there. As everyone comes up the path we're telling them it's too windy you'll be turning back. Maybe some of them will make it to the top today. Elsa was that waterproof? So abandoned trip to the summit of Helvellen. Maybe if I'd gone on my own I'd have maybe made it to the top. But with the kids just too dangerous. Just too windy. So we've gone as far as we can and we've come back down back in the car park now we're going to get changed, get into dry clothes. We're going to drive to Ambleside and have something nice and warm to eat and drink. All right so that's it from the Summit Club for 2021. We'll see you for Summit Club 2022. Maybe we'll go to the top of Ben Nevis in the summer. you


Welcome to the Dr. Gundry Podcast. Do you ever experience racing thoughts, restlessness, or the feeling of impending doom? Well, if the answer is yes, you are certainly not alone. As a matter of fact, feeling this way is extremely common, particularly now. According to the Anxiety and Depression Association of America, roughly 40 million adults suffer from anxiety. But very few get the help that they need. And let's face it, this worldwide pandemic is not exactly helping our anxiety levels, or our depression for that matter. The good news is, being creative and expressing yourself through art and writing can help reshape your mindset for the better. And my guest today wants to help. In a moment I'll speak with Mira Lee Patel, Mira is a talented artist and author. She's also a columnist at Spirituality and Health, where she writes and draws about mental health. And she's got a new book coming out shortly called Create Your Own Calm, a journal for quieting anxiety. A book of beautiful illustrations, inspirational quotes, and writing exercises. And she's had many more. I happen to have been reading Start Where You Are, so I started Where I Am.  So on this episode of the Dr. Gundry podcast, Mira and I will talk about how art, writing and reflection can help you ease your anxiety and live a better, more fulfilling life. Mira, thank you for coming to the program. Thank you for having me. I'm very happy to be here. Welcome. First of all, tell my listeners a bit about yourself and how you became an artist as you didn't start your career off there, right? No, I went to school for English and Journalism and I was all set to become a journalist. After graduating, I got a job at a technical publishing company where I edited papers written by electrical engineers. This was a huge win for my father, who is an electrical engineer, but it was not really, you know, a great fit for me. And after doing this job for about a year, I started to feel a big sense of disconnect between how I was spending all of my time and who I was. And I found that I was unable to recognize myself. And so I started painting and writing again as simply that, as a way to reconnect and to figure out where had I gone? And after I started drawing, I started selling my work solely online, doing little markets and things like that. And I saw that there was a whole creative community that contrary to what I had been taught and what I had grown up knowing, these were people that had creative careers and were making a living. And they had families and they had homes and they had built a sustainable lifestyle. And I decided that that is what I wanted for myself. And so I continued working. I stayed at my job for seven more years while freelancing full-time. And it was after that, after seven years, I was finally able to quit and pursue a career as a full-time writer and an artist. Ah.  And we know often the pressures of actually any first-generation American that their parents usually want them to pursue expected careers. And those careers are often being a doctor, or being a lawyer, or being an engineer, or being what our parents assumed would be a proper career here in America. And were you subject to those same sort of pressures? Yes. There was a big emphasis on good grades, good education, and the reason for that was to secure a good job and have stability. And while I now understand those and maybe even understood them while I was growing up, it didn't make it any easier to live a life for somebody else. I very often felt that I was living a life for my parents and not for me. And the pressures, I think, that first-generation children feel evolved into a lot of different emotions that can lead to anxiety and depression, namely, I think, shame for not wanting the same life as your family, and also a lot of guilt because, you know, firsthand what they have sacrificed and what they have given up to give you such a stable and safe place, the complete opposite of what they had growing up. That brings me to something else we talked about. You talk about growing up with a scarcity mindset, and I think you just alluded to that. Give me some more of what you mean by a scarcity mindset. So a scarcity mindset, the way I grew up in it, is the belief that there is never enough. And that creates competition not only with people around you when it comes to getting into a school or looking for a job or accepting an assignment, but it also created a lot of competition for me within myself, between the person that I felt I was and the person I felt I had to be. And scarcity mindset convinces you that if you don't accept every opportunity that comes your way, even if it's not a good fit for you, that there will never be another one. If you spend a little bit of your savings, you will never be able to replenish it. If you leave a relationship that isn't healthy for you, you may never find another one. And so it does a really good job of keeping you in the same place and limiting your growth and limiting the amount of change that you not only become comfortable with, but allow yourself to create. As you're growing up, was art, was drawing or writing or painting one of the ways you dealt with this growing up? I mean, were you interested in these things from day one? Yes, I was a very creative child, a very creative teenager, and my parents were extremely encouraging. I don't mean to say that they weren't supportive of my interests. They were very much so. They just didn't believe that you could build a career off of it. It wasn't a stable career. So they encouraged me always to pursue my hobbies and my interests, but to have something extremely stable that could hold me upright through it all. And that's not a bad goal of any parent for their child. Of course. Your parents don't want you living in their basement when you're 30 or 35 years old, at least hopefully not. So how long, so this obviously created a lot of anxiety for you particularly, because your parents I'm sure are very persuasive that you need to do something to put food on the table because we're not going to be here forever for you. Absolutely. So how do you balance that? Do you write journals? I write journals. I think the important thing for me was to learn and separate which of the fears that I had within me were mine and which ones had been given to me by my parents. So because I had been raised with scarcity mindset, did that mean that I as a functioning adult also believed in that philosophy? That I really believe that if I turned down an opportunity, I would never be offered another one. And so start where you are. My first journal is, it's a journal for self exploration. It encourages introspection, which all of my work does, because I have found that the greatest freedom in overcoming my fears and overcoming my anxiety and creating a life that I am proud of is all rooted in knowing myself better and getting to know who I am, what I believe in, what my values are aside from the ones that have been taught to me by not only my parents, but the people in my life, society, culture, etc. So the root of it for me, what I've learned is to separate yourself from all the noise and really figure out how to hear yourself. Now, were you able to do that all by yourself? Did you need to find mentors and guides to help you understand this? How did this knowledge, how did you acquire this knowledge? You know, I haven't had any mentors or teachers in that regard, but I will say that I was raised with Eastern philosophy and that has helped me very much so in finding connectivity within myself and within the world. And it has also been a big underlying current between having the ability to empathize with other people and seeing myself inside other people. And so those kind of core philosophies that I was raised with, I think, have really helped me hone in on what my perspective of life in the world is and make these changes for myself, even though they went against a lot of the culture that I was raised with them. So you mentioned that you kind of stuck with this job that you hated for seven years. Yes. And I was on doing the Skinny Confidential Podcast a little bit ago. And one of the things that struck me as good advice, and it sounds like you did this, is don't necessarily leave a job you hate, but have a side gig that you love. And I think many people make the mistake of having a stable job that really isn't what they really want to do. But it does put a roof over your head and does let you get the essentials while pursuing something else. In fact, the host Lauren was a bartender. And she learned more about life bartending and enjoyed it far more than what she was doing as her day job. So was that what you were doing? Did you have a side gig to figure out that you could actually enjoy this and do this and maybe make a living? And then you jumped? Yes. So the whole time that I was working at my full-time job, I was also freelancing as an illustrator and a writer. And I agree with you, and I don't think that my parents were wrong in instilling the notion of stability within me. But I will say that I stayed with my job out of fear, a fear of not having stability, a fear of losing my independence. And those fears and anxiety kept me there for perhaps longer than I needed to be. But I'm often asked, you know, if you did it again, would you do it differently? And the answer is no, because I agree with Lauren. I learned discipline. I learned how to create structure for myself. I learned how to work very hard, how to compartmentalize, how to multitask, how to balance two jobs at once. And those are skills that are a huge asset for me as somebody who now works for herself. It's not easy to run a business. It is not easy to be a creative that runs a business. There's so much of having a small business that has nothing to do with painting and writing.  So I do contribute all of the experience that I gained at my full-time job with allowing me to successfully run a business now. That is actually incredibly insightful. I mean, that is a real compliment because you're right. Creative people oftentimes do not do mundane tasks well or want to do mundane tasks. How's that? Is that a good way of describing it? Yeah. Yeah. And that's great. I mean, you literally learned how to keep, in a way, blinders on. And you learned things, even doing things that you really didn't want to do. Yeah. And I think it also instilled a sense of tenacity within me, which I think is really important for any person who's going to work for themselves.  If you don't have a boss, if you don't have somebody that you have to answer to, it can be incredibly easy to just slip away from it all. So I do think that it instilled that work ethic, that dedication, and that drive that I think is imperative for any freelancer to succeed.  Are creative people, let's just generalize, more subject to anxiety and depression than people who don't consider themselves as a creative person? I don't think they're necessarily subject. I go back and forth. I do find that in my experience creatives are extremely sensitive. They are very in tune with their emotions, and they are very prone to examining every single little thought that comes into their brain. And being that hyper aware of your own thoughts can lead to a lot of anxiety. So from my experience with my peers, a lot of us do suffer from anxiety. And with the internet being the number one place to show our work and to get jobs and to sell our work and kind of build a career, there's a lot of imposter syndrome. There's a lot of self doubt. There's a lot of self loathing that comes along with seeing and comparing ourselves by their creatives on the internet. And so I do think that having a mental health practice and knowing your own brain and the tendencies that it slips into is really important in managing your health. So can you can you give me two or three examples that people watching or listening can use to ease their anxiety? And you brought up some really good instances of these thoughts pop into your brain. And how do you figure out which is an important thought and which one isn't? I think that something that I emphasize a lot in my work is using once you figure out what exercises work for you, because there are such a wide range and everybody deals with anxiety and depression differently. Once you figure out what works for you, it is important to cultivate a practice and kind of rewire your brain so that it reacts to panic and fear and anxiety differently. And so one of the simplest exercises I think anybody can do almost anywhere that you are is to harness the power of repetition. And so I encourage people to pick a word or a phrase that feels calming to them. And I often these days when I'm having trouble falling asleep, I literally use the word calm as my basis for this exercise. And you want to either write or draw it over and over again.  And you want to repeat the word. And if you don't want to write, you can draw a shape, a triangle or a square and begin filling it in with doodles. And the point is to get you out of your head and into kind of a state of the axis meditation where you can be in the present and you can turn off the cycle of anxiety that that, you know, tends to turn in our heads. Another anxiety, another exercise for anxiety that I like again that you can do anywhere. And I don't know if you have this experience, but doctors offices waiting while you're waiting. That can be a place where people feel a lot of anxiety. And I encourage them to sit and notice where they feel tense within their body. Where are you holding the anxiety? What parts of your body feel hardened and tightened?  And the last part of this, which I think, you know, a lot of us probably skip over is I really encourage people to know how did you feel before and after doing this exercise? And that is important for your own, your own benefit and your own knowledge in realizing what your body and your mind react to and what is helpful and what is not. Those are great. You know, and of course, in the Eastern tradition, the art of breathing is probably one of the best possible ways we can calm our mind and our body. But I want to get back to doodling. I want to get back to doodling.   You'll never accomplish anything because you're busy doodling. I personally think it's an incredible use of time. And I think that when you're doodling, you're endaging different parts of your brain that aren't normally activated. I think, as I mentioned before, it's a great way to participate in active meditation, which a lot of us, especially in this time and space need, we don't have the capacity to go from go, go, go to sit, you know, on the floor and clear your mind for 20 minutes. It's simply not possible. So a good transition is active meditation when some part of your body is moving, but you're still focusing on calming your body, calming your mind, and staying in the present. And so I find doodling to be a great active meditation. It's a great way for you to be in the moment, to be a little bit more still, to get into that flow state that can be really hard to tap into. And yet it keeps you occupied. And for a lot of us, simply having something to do, fidgeting, doodling, repeating a mantra, that can be very self-soothing. And it can make it easier for us to turn towards things like meditation. I'm glad to hear you say that, because actually all through college and medical school, I doodled on my notes everywhere. And even once a week in the hospital, we would have a cardiac cath hour and a half where we'd review films and plan operations and of hearts.  And of course, I'd be doodling watching these things. So thank goodness it was okay for me to doodle. I feel much better about myself now. Yeah. Actually, I've never told anybody that. Yeah, yeah, I was a doodler. So I guess I did okay. I think it worked out great for you. Yeah. So where, okay, so where do we cross the line between doodling and artwork? Where do you see, you know, your art? Let's start with your art. Where do you see that helping you deal with anxiety? My artwork, my artwork becomes an active meditation. Not, I will say not as often as I wish for it to, because it is hard to turn my mind off of, but I don't think that, I don't believe that the end result, what a painting, what some might call a painting, I don't think that paired, you know, compared with a doodle or a scribble, what somebody would call a doodle, there's no difference in either of those when it comes to how it releases stress. What I'm not explaining this correctly, what I mean to say is, what it looks like doesn't matter as much as the act of doing it. So it could be a doodle, it could be an oil painting, it could be writing a poem.  And if your brain is with you in that moment, in that activity, then I think it could be very helpful as a meditation and as a way to calm yourself.  Or did the feedback come from showing these things, you know, to friends and trying to sell them? Tell me how that got started. I think asking any artist if they like their work, or if they think they're good at it is dangerous, because I will say that even now, I don't, I don't think, I don't think my work is where I want it to be. And I don't think my skill level is where I want it to be. It's a constant wanting to be better and wanting to produce better work. Have I found success with my work? Yes. And do people want to buy my work? And does that make me feel good? Yes. But my expectations for myself and for what I produce are always climbing and they're always changing because I as a person am changing. And if I am making honest and genuine work, which is a reflection of me, that means that as I change, the work is always changing. And it always feels that I am trying to catch up to, I am, there is always a lag between my physical, my physical ability to produce what is in my head. So it's a constant evolution. And it's a constant learning and trying and failing and continuing to try. Well, that's a very good insight as well. I'm a fan of a rock band called Dawes, D-A-W-E-S. And their lead singer and writer really started as a writer, a lyricist. And they had a good commercial success, I guess, with their first album. And then he says, oh, my gosh, I've got to become a much better guitar player. I have to become a much better musician because, you know, what do I do next? And it's exactly right. He had an initial success and that propelled him to take his level of craft to a higher level. Absolutely. And, you know, I think that happens in all art forms. It certainly happens as a surgeon. You're always trying to perfect your craft and it's never perfect. I agree. And I also, I love that you mentioned yourself as a surgeon because something that people also ask me is like, how can I become creative? And I am a big believer that creativity is not reserved for visual, you know, or performing artists. Creativity is about perspective and how you approach whatever it is you're doing. And so for you, that is medicine and surgery. And there is a lot of creativity. I know that you put into that. And I just wanted to mention that because for anybody who's listening that feels that they're not creative, I think creativity can be how you approach a conversation or how you're doing the dishes or it can be part of your morning walk is something that is applicable anywhere to whatever you might be engaged in. Another very good insight. You have to do something good at anything.  Yeah, good point. OK, now this may sound controversial, but anxiety isn't isn't always a bad thing, right? I mean, isn't anxiety one of the things that, you know, is a superpower for artists in a way? I think it is. I think that anxiety is often rooted in a fear and that particular fear is usually trying to tell you something. And in my experience, it's trying to tell you something that is very valuable or important to you. And if you take the time to pull that fear and anxiety closer and examine it and ask yourself, you know, why do I feel this way? What am I afraid of happening? If this fear comes true, how will I handle it? If you answer all of these questions, it leads you down a path of self exploration.  If you don't know what you want, you can't go after anything. And so I do think our anxieties and fears have the ability to lead us down introspection. I also think that anxiety, if you are careful not to turn it into shame, if it is something that you can be open with yourself about and maybe talk to trusted people about, it can lead to very beautiful vulnerability. And vulnerability is another superpower because it allows you to connect with people. It allows somebody to look at you and to see themselves in you. And I think some of the most beautiful relationships, connections, the feeling, the very, I think, rare and coveted feeling of being seen for who you actually are. Those are all those are all effects of vulnerability. And so those are two ways that I think anxiety can truly be a superpower. OK, that's a good segue. You tell our listeners a little bit about create your own call and the inspiration behind that. Sure. Create your own calm is a journal, an interactive journal for quieting anxiety. And what that means is that it is filled with exercises and prompts that the reader has to participate in in order to feel the effects. And by my philosophy behind the journal is really rooted in self-acceptance because I have found that my biggest source of anxiety has been when my heart and my mind and my body have all been battling against each other, accepting my anxiety, accepting that I have certain fears and that I'm going to work on getting to know them and understand what they were trying to tell me has helped me soothe my anxiety and not eradicate it, but learn how to manage it. I also approach the exercises in the book in a myriad of different ways. We touch on daily meditation, physical exercise, nature, creating meaningful connections within yourself, your relationship and your work. I kind of tackle it on all fronts because the root of everyone's anxiety is different, but I do believe that it is usually resting within a place of disconnect. There is a disconnect between you and something you need, and that is where anxiety grows. So the book really tries to help you identify what your disconnects may be and help you figure out what is the best way for you to manage those. So your book is full of inspirational quotes. You got any favorites or one favorite? I actually do have one favorite. I wrote it down for you. It is by Albert Einstein, and it says, life is like riding a bicycle to keep your balance. You must keep moving. And I am a big subscriber of that philosophy. My personal mantra is action changes attitude. And I have lived the belief that taking small steps every day, small, incremental, almost invisible steps will eventually lead to a whole new life.  The feeling itself won't go away on its own. You must take an action, and then the feeling will change. That's a very existentialist philosophy that I completely agree with. You got to take an action. I'm sorry about that. Yeah, that's all up to you. Yep. So what's the most rewarding part of what you do now? Is there anything? Give me an example of an impact that you've had on another person that really resonated with you. I receive a lot of letters from teachers and therapists that use my journals with their patients. And I have to say that that is something that stuns me every time and that I feel so grateful and honored by to have created something that a licensed therapist and teacher believes is useful in their practices. And I get these letters, you know, weekly. And I don't think I would ever stop pinching myself or thinking how amazing it is to make something from the heart and find that it has the ability to help somebody else. That's fantastic. So OK, now I got a question for you. I have a very dear friend who is very spiritual and she is a huge believer in journaling and even has some books on journaling. You probably know her name, but I'm not going to tell you. What if you're what if you're not a journaler? Is it possible to do this without actually writing these things down or is writing part of the process? That's a great question. I think that, of course, it is possible to do any of this work without writing it down, but that the writing makes it far easier. I find that writing the thought down is almost akin to physically taking it from your mind, taking it out of your mind.  So I I understand somebody who feels they're not a journal or and sometimes I think that word itself can can turn people away. But everybody writes right. You write a grocery list. You write down notes.  I would encourage people to reframe the way they think about journaling and to try it, maybe, if they never have and see if it works for them because they do find that again, that activity, the physical act of writing is very beneficial when you're doing introspective work. Good point. And I obviously journal in another way. I've written over 300 medical papers and I've written a bunch of books. So, yes, and you're right. I, in a way, don't like to write, but I write all the time. And it's, yeah. All right. Well, Mira, you know, thanks so much for joining me today. Where do people find you in your work and where is the book going to be available and websites, et cetera, et cetera? My website is miralee.com, where they can learn more about my work and my books. Create Your Com will be available everywhere, online and in bookstores everywhere. And I post and in most active on Instagram at Miralee Patel. People, she's a great resource and search her out. And obviously, a lot of wisdom there. So thanks again for coming on the program and good luck with the book. And please, in this time of anxiety through the roof, it's time to take some of her recommendations to heart. And it's going to help you a lot. All right. Thank you very much. Thank you so much for having me. OK, it's time for our audience question. Ishtar0077 on YouTube wrote in and asked, can you talk about colon hydrotherapy? Is it a good idea to do it? You know, that is a great question and happy to talk about it. So those of you who don't know, it's often called colonics. And the history of colonics is fascinating. And I'll bear with me for a minute. It back in the late 1900s, there was a theory that became incredibly popular to explain diseases. And it was called auto intoxication. And the theory was that bacteria in your gut, in your colon and in your mouth were the cause of most diseases. Now, if you think that sounds familiar, it's that we are now rapidly embracing the fact that Hippocrates was right that all disease begins in the gut. And in the auto toxicity movement, it was that the bacteria in the gut and the mouth were causing intoxication of the human being with various bacterial particles. And that in its extreme, which actually happened in the 1930s and 1940s, people were literally having their entire large bowel, their colon removed surgically. And all their teeth pulled to stop auto toxicity. It went that far. But prior to that, the theory was that these bacteria in your large bowel were the cause of auto toxicity and that they should be removed by literally taking a garden hose and cleaning out your colon. And this is where hydrotherapy really got its start.  You've got four to five pounds of incredibly important bacteria, fungi that not only shouldn't be washed out, but should be fostered. And as you know, most of everything I teach is you got to give the gut buddies what they want and they, in fact, will take care of you. And you'll see in the upcoming book, The Energy Paradox, how we're going to take that to the next level, because without the products that those guys produce, you're actually going to be sapped with energy. So, no, I am not a believer in colon hydrotherapy. I know how the theory of how it might help come about. But quite frankly, it's the last thing you really want to do to support your health. Auto intoxication. Thankfully, that theory died to horrible death after many thousands of people had their colons surgically removed in their teeth pulled, and that's not the way to good health. So, but great question. OK, review of the week. Following my recent chat with Mark Manson, the author of The Subtle Art of Not Giving an FUCK, Carol Gray on YouTube wrote, I really enjoyed this. It warmed the cockles of my heart. It's very uplifting, just hearing you both sharing and laughing. Well, we had a good time with that. That was actually the first time I had ever met him. And if you haven't listened to it, I actually thoroughly enjoyed that. And I guess we did have a few good laughs, but thanks for noticing. We were having a good time and hope you liked it. Thanks. Before you go, I just wanted to remind you that you can find the show on iTunes, Google Play, Stitcher or wherever you get your podcasts because I'm Dr. Gundry and I'm always looking out for you.


Morning Trotters, Patrick Mungley here with another tip. I want to draw your attention to a developing opportunity in the dollar year. I have two timeframes here on the left hand side. We have the daily timeframe. Friday we got the test of that long-awaited 10430 area. We saw a key day reversal pattern taking out a number of prior days ranges. And now I want to draw your attention to the intraday chart, so looking on the hourly timeframe. Two areas of interest for me. I'm either looking for a pull back into the weekly and daily pivot in around 10530, watching for bullish reversal patterns there to set long positions. Or I'm looking for a close through the monthly pivot at 108608 also to set long positions. Ultimately now I'm looking for a move up to test towards 108 is the primary upside objective. As always traders, plan the trade, trade the plan and most importantly manage your risk. Until next time, thanks very much.