Search DominoPower's 11,422 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
PROGRAMMING POWER
Recursion: the good, the bad, and the alternatives
By Ian Murray

Sometime back, we looked at recursion as a way to solve some problems not easily solved in other ways. Unfortunately LotusScript recursion does have its limitations and in this article I will be discussing how to discover what those limitations mean for you and your code, and how you can avoid them.

To recap, recursion is where a process is designed to solve some problem by breaking the problem down to a single indivisible case and calling itself to deal with the "rest of the problem", where the "rest of the problem" is a smaller, similar problem to the original problem. This kind of effect can be seen in the natural world.

For example, with reference to an apple tree, a "tree part" is a piece of wood with either several smaller tree parts coming from one end, or with an apple or leaf attached to the end. If you set the initial tree part to be the trunk, then we have successfully described a tree -- almost. We are forgetting about the root. In fact the same process can be applied to the root, as this can be recursively described.

To find every apple on the tree, we could have some pseudo-code like:

Sub ExamineTreepart(Treepart):
If Treepart has apple then
Pick Apple
Else
For all attached treeparts
ExamineTreepart(attachedTreePart)
End forall
End if
End

Trees are everywhere in computing: filesystems, indexing (B-Tree, in Domino's case) and pretty much any kind of system hierarchy -- so it's important to be able to deal with them, from a programming point of view.

Most agents take a linear path from the start of the program through to the end, although we may have jump out to take advantage of re-usable code such as objects and subs/functions. We may also perform loops, such as "while... end while" or "forall". This is known as iterative programming. Any iterative method can be reproduced using recursion.

For example, printing a string could be described as "print the first character, then print the rest of the string by printing the first character of the remainder, then print the rest of..." as you can see here:

Sub PrintAscii(Byval sToPrint As String)

' A "string of characters" can be described as a single character followed by nothing or a string of characters

Print Asc(Left$(sToPrint,1)) 'The first character
If Len(sToPrint) > 1 Then
PrintAscii(Mid$(SToPrint,2)) '... The rest
End If
End Sub


1  ·  2  ·  3  ·  Next »
Other articles you might like
Home > Lotus Technologies > LotusScript (64 articles)
   When the debugger won't debug hidden code that isn't hidden
   What to do if the LotusScript debugger won't single-step over code
   Little known traps about Lotus Notes fields
Home > Tips & Techniques (102 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   A faster way to repair corrupted server files
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
New Notes/Domino Technotes published about Chile's extended daylight saving time
SnnT: How to prevent Google from listing your Sametime Server
How to send someone an email that shows your calendar availability
"The collection has become invalid"
More XPages onclick event weirdness...
Domino 8.5.1 Fix Pack 1 Interim Fix 1 (8.5.1 FP1 IF1) - DAOS Fixes
Domino Designer 8.5 Tip: Where Working Sets Are Stored
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- Advertisement --

Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.

The many included activities and demos will make you a pro! Expert instructor help is a click away.

Click here to try a FREE demo course!!

-- Advertisement --

Integrate your Notes Applications with Microsoft Office and Symphony
Integra for Notes Integrates Microsoft Office and/or IBM Lotus Symphony
Requires NO change to the design of the appliation or Installations of DLL's and EXE's
  • Integra is a ready to use solution, enhance static reports with Excel data analysis, pivot tables, macros
  • User friendly aproach, using a point and click access to features
  • Reports from any Lotus Notes databases
  • Runs reports through a Notes client, web browser and scheduled basis
  • Allows use of LotusScript for advanced data manipulation
  • Enables self service reporting capabilities to end-users


Learn more at www.integra4notes.com.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login