# Creating Temporary Variables

**General**

LoanPro provides many useful loan variables that you can use. However, at times some of your computation rules will become very complex and will use the same computed value or expression repeatedly. Copying and pasting these expressions may work, but it can make a rule hard to read. For example, suppose we needed to use the expression (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)) several times throughout a computation rule. We could copy and paste the expression, but our computation rule could end up looking something like this:

(- 8 (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)) (* 2 4 (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4))) (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)))

The computation rule above is very long and hard to read. Now imagine that in the repeated expression each number represented a different loan variable. Our computation rule would get even longer very quickly. It would be nice if we could use a letter to represent our repeated expression, that is, if we could do something like this:

Let x = (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4))

Then the same computation rule as above would look like this instead:

(- 8 x (* 2 4 x) x)

Now the computation rule is so much easier to read, and we can easily see what’s going on.

Fortunately, Lisp lets us do this by using the LET operator. By using the LET operator, we can define complex expressions once and then repeatedly use them throughout our computation rule.

*How to Use the LET Operator*

Using the LET operator is a bit different than using other Lisp operators. Below is the basic syntax:

(let[var1 *value* var2 *value*] (*expression*))

Let’s look at the syntax in sections. We’ll start with the very first part:

*(let*

The very first part tells the system “We want to create some variables.”

Now let’s look at the next part:

[var1 *value* var2 *value*]

This section tells the system what variables we want to make and what values we want to give them. For example, say we want to set the variable “x” to equal 5, we would do [x 5]. If we wanted to add the variable “y” and set it to 10 we would do [x 5 y 10]. It can be thought of as saying: Let x = 5 and y = 10.

Finally let’s look at the last part of the LET operator syntax:

(*expression*))

This is the Lisp expression that we want to be able to use the variables for. Outside of this expression, the variables don’t exist, so if you set x and y in the LET command, you can only use x and y in this expression.

*Examples*

Now let’s apply the LET operator to the expression and computation rule we used at the beginning of this article. We wanted to let x = (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)) in the computation rule (- 8 x (* 2 4 x) x)). In Lisp, we would set it up like this:

(let[x (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4))] (- 8 x (* 2 4 x) x))

As a reminder, without the LET operator, the same computation rule looks like this:

(- 8 (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)) (* 2 4 (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4))) (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4)))

As you can see, the computation rule is a lot smaller and easier to read when we use the LET operator.

Please remember that you cannot use variables outside of the given expression. For example, the following won’t work because we’re using the last “x” outside of the LET operator’s expression:

(+ (let[x (+ 8 (* 5 9 (/ 4 3) (+ 4 8)) 19 (- 9 4))] (- 8 x (* 2 4 x) x)) x 9 19)

The LET operator’s expression defined above is (- 8 x (* 2 4 x) x)). The x in “x 9 19” is outside that expression, so the last x is invalid and the rule won’t work.

Here is an example of using LoanPro variables in a computation rule with the LET operator:

(let[x (- status-amount-due status-due-fees)] (/ x 2))

Here the variable x is set to the difference between the amount due on the loan and the due fees. In the expression we divide this number by 2.