|
|
|
|
|
|
|
|
|
|
|
|
|
|
SIMPLIFYING ADVANCED PROGRAMMING TECHNIQUES
Using recursion in LotusScript
By Greg White
LotusScript is a powerful programming language that gives developers the ability to utilize advanced programming techniques. One of these techniques is recursion. Many developers hesitate to use recursion, preferring to use techniques with which they're already familiar. But using recursive functions can greatly simplify your code, if you implement them correctly.
What is recursion? Simply defined, a recursive function is one that calls itself. While that definition may be simple, writing a recursive function for the first time can be difficult because it requires a different method of thinking.
Most functions are coded in a fairly straightforward fashion -- you progress from point A, to point B, and end at point C. You may have loops and If Then statements, but you can easily visualize the function in a linear fashion. Recursive functions, however, take an inside-out approach to arriving at an answer. Consider the recursive function below, which calculates the factorial of a number. The factorial of a number is arrived at by multiplying it by all smaller integers. So, the factorial of 3 (denoted as 3!) is equal to 3 * 2 * 1, or 6.
Function factorial (i as integer) as long
If i = 1 then
Factorial = 1
Else
Factorial = i * Factorial(i -1)
End If
End Function
|
Stepping through a recursive function Let's step through this function to see how recursion works. We'll assume that you've called the factorial function with a value of 3 as the integer parameter.
You can easily see that since 3 is not equal to 1, the line of code you're concerned with here is:
Factorial = i * Factorial(i - 1)
|
In English, this line would roughly translate into "The factorial of 3 is equal to 3 times the factorial of 2." So, in other words, the factorial of 3 is equal to 3 times some as of yet unknown value.
Let's figure out that unknown value. If you were to call the factorial function with a value of 2 (which is exactly what this function is doing), you'd see that the factorial of 2 is equal to 2 times the factorial of 1.
You're almost there! Call the factorial function with a value of 1, and the answer is simple: The factorial of 1 is 1. Now what?
Let's take a look at the results we've come up with so far:
3! = 3 * 2!
2! = 2 * 1!
1! = 1
|
Working from the bottom up, you can easily see that the factorial of 3, or 3!, is equal to 6.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
PDF Conversion for Lotus Notes
Convert Lotus Notes documents to PDF for sharing, archiving or web printing.
- 1-step PDF: As easy as clicking a Lotus Notes toolbar icon
- Archive email folders or views as a self-contained PDF
- Convert any document collection into a PDF file
- Produce print-quality output from Web applications
- Client side or Server side conversion
- Doesn't require any DLL files
- LotusScript API for developers
Ready to learn more? |
-- Advertisement --
Easy Domino Access: Remove Passwords, End Login Prompts, Reduce Password Management
PistolStar's Password Power provides browser-based single sign-on to Lotus Domino, Sametime and Quickr with the enhanced security of the Kerberos or NTLM authentication protocol.
- Full support available for NTLM authentication protocol in non-Active Directory environments
- Seamlessly integrate Microsoft Active Directory and the Kerberos authentication protocol
- Leverage Active Directory password policies to unify Lotus applications
Learn more about Password Power's powerful, advanced functionality. |
|
|
|
|
|
|
|
|
|
|