 Okay, now that we've laid some groundwork we can show a few practical examples and we'll start with writing a factorial function. A factorial, if you don't remember, is we take an integer number and we multiply it by every integer up to that integer. So say the factorial of 6 is 6 times 5 times 4 times 3 times 2 times 1. And then the factorial of 0 is a special case that is 1 for some reason. You'll have to ask a mathematician why that's the case. Anyway, we use factorial as a classic example of a recursive function in programming because it's very neatly recursive. The factorial of 6, for example, is 6 times the factorial of 1 less than 6, the factorial of 5. And likewise say the factorial of 15 is 15 times the factorial of 14. And so here when we have this factorial function created with the def n form, which recall is a macro, that's just a convenience for defing a fn form. In this function we first have a condition that tests well is n the parameter equal to 0, that's what the equal sign is as an equality test. And if so, if it returns true, then the f form returns 1. And so the function returns 1. But if n is not equal to 0, then we return the value of this multiplication of n times the factorial of dec n, 1 less than n. Dec stands for decrement recall. So dec returns 1 less than the value of n. Now there's a problem with this factorial function because it only actually works for integer values up to 20. And anything greater than 20 is going to trigger an exception because it turns out that the factorial of integers, they grow very, very rapidly. So the factorial of 20 is already a very large number. And the factorial of 21 is an even larger number. And it turns out it's so large that it's actually exceeding the capacity of the java long number type. It's too big to fit in the range. So we get this overflow exception. So how do we fix this? How do we have a factorial function that will work for arguments greater than 20? What we can do is make a very simple change. Instead of the ordinary multiplication function we'll use asterisk apostrophe, which is a special multiplication function that will accept as argument and returns arbitrary precision numbers, that is numbers of type closure dot lang dot big int or dot big decimal, the two arbitrary precision number types in closure. With that one little change, this factorial big int function will work for values greater than 20. However, for even larger values of n, we'll run into another problem eventually, not numerical overflow, but a stack overflow, because our function here is defined recursively. And so when the value of n is very, very large, we're going to be making that number of recursive calls and each recursive call is adding another frame on the stack. And past a certain point, you're going to exceed the size of the stack, even on modern systems, which will have stacks of say a few megabytes or so. On my system in testing, when I invoke this function with the argument 11,439, that is when I would first get a stack overflow. On your system, though, could be something else because different systems have different size stacks. How do we fix this problem? Well, you may recall that the recur special form allows us to make a recursive call that doesn't consume extra stack space that just reuses the existing stack. The problem though, the reason we can't use recur here is that the recursive call is not in tail position. And the optimization that recur uses the tail call elimination only works when the recursive call is in tail position. So you can't use recur here. In fact, the compiler won't compile this function. So to fix the stack overflow problem, we need to write a factorial function that doesn't use recursion, that just uses a plain old loop, a loop form. So here this factorial big inch loop function does just that. First, we have an if that tests whether or not n is equal to zero. And if so, then the factorial function returns one. In all other cases, though, we need to loop. And in this loop, the first iteration we bind to val and I the value n. And if I is less than or equal to one, then we return val. Otherwise, we're going to go through another iteration in which val is bound val times one less than I the deck of I and I is bound one less than I. So note that effectively, I starts out as the value of n and in each iteration, that's one less, until in the last iteration, when I is equal to one, then the if condition is going to test true. And so it's going to return val, the loop is going to intern return val and the outer if is going to return val. And so the function will return val. Meanwhile, in each iteration, val will be accumulating the result. So if the argument to the function is say five, then in the first iteration, n has the value five, then in the second iteration, it has the value of five times four 20. And then in the third iteration, it is the value 20 times three, which is 60. And so forth until the last iteration, where val has the value 120, because the factorial of five is 120. So there's our working factorial function.