1. ## Recursive- dangerous!

I can't remember whether I spread this on the toast, but here it is. One of the best arguments EVER for being aware of the dangers of recursive functions.

The challenge is to report back with the value of Ackerman(5,5)

<pre>Public Function lngAckerman(ByVal intx As Integer, ByVal inty As Integer) As Long
' Procedure : lngAckerman
' Description: Calculates the Ackerman function.
' The Ackerman rating of a language is of interest.
' Calculate a small table of values for intX ranging from 0 to 5.
' Each column can be represented by a formula.
' If a language supports that formula, it has that Ackerman rating.
' Inputs: Two numbers.
' Returns: A rather large number.
' Assumes: Nothing
' Side Effects: Will probably blow stack space on any computer
' in existense when Ack(5,5) is attempted.
' Tested: By the calls shown below.
If intx = 0 Then
lngAckerman = inty + 1
Else
If inty = 0 Then
lngAckerman = lngAckerman(intx - 1, 1)
Else
lngAckerman = lngAckerman(intx - 1, lngAckerman(intx, inty - 1))
End If
End If
'Public Sub TESTlngAckerman()
' Dim intx As Integer
' Dim inty As Integer
' For intx = 0 To 3
' For inty = 0 To 3
' Debug.Print "x=" & intx & " y=" & inty & " Ackerman(X, y)=" & lngAckerman(intx, inty)
' Next inty
' Next intx
'End Sub
End Function
</pre>

2. ## Re: Recursive- dangerous!

Recursion is just another tool in the programmer's toolbox. The programmer needs to know and use the right tool for the right job. In the example you posted, recursion doesn't appear to be the right tool for the job.

I don't want any programmers to shy away from recursion. Just know when it's not appropriate.

[img]/S/sarcasm.gif[/img][img]/S/smile.gif[/img] What's next? Subject: LOOPING - DANGEROUS!

Mike

3. ## Re: Recursive- dangerous!

I agree. The same arguments can be applied to classes, inheritance, and a host of other tools that can be improperly used. And unfortunately, there is no substitute for learning how.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•