RecursiveActions
RecursiveActions is a programming pattern in which an action or procedure is defined in terms of itself. The pattern is well suited to problems with recursive structure, such as trees, graphs, or spaces that can be divided into similar subproblems. A RecursiveAction includes a base case that terminates the recursion and a recursive step that invokes the same action on smaller subproblems. The current state is typically threaded through each invocation, allowing results or effects to accumulate as the call stack unwinds.
Operation and structure: At each invocation, the action performs its local work, checks the termination condition,
Applications: RecursiveActions appear in traversals of hierarchical data structures (such as trees or directory trees), generation
procedure RecursiveAction(node, context)
if termination_condition(node, context) then
perform_pre_processing(node, context)
for each child in node.children do
RecursiveAction(child, updated_context)
perform_post_processing(node, context)
Notes: Recursion depth and call-stack usage are key considerations. For very deep or broad structures, an
See also: recursion, depth-first search, backtracking, divide and conquer, tree traversal.