My Patient Husband, the inveterate dyed-in-the-wool geek that he is, grabbed the Bible Of Computing in order to look up a bit about recursive functions.
If you’ve never been to our house, you don’t know that sometimes he and I will be working side by side, never talking but very much together. In my head, I’m telling stories about angels, and in his head, he’s programming great big machines and solving computing problems. The problem in this instance is that Embedded Matlab doesn’t allow for recursive functions, so he needed to rewrite a function in a non-recursive way. If you’re looking at the screen kind of baffled, a recursive function is one that calls itself while it’s running. Kind of like if I told you that a habit is an action you do habitually.
At any rate, there he is, with his copy of “Data Structures and Algorithms” by Aho, Hopcroft, and Ullman, (it’s got great character development, but it could use some better scenery) when abruptly he exclaims, “Those whackos!” and starts laughing.
Because he’d gone into the index to look up recursive functions, and there are three pages listed.
The last of the three listings for recursive functions is the index page on which the term “recursive functions” appears.
Oh, those wacky computer scientists!
That is absolutely hysterical.
If you want an easy example of a recursive function, think of a Fibonacci sequence. You start with 0 and 1 and then keep generating numbers by adding the last two so
0 1 1 2 3 5 8
You get the idea. A function to generate this would take in two numbers, spit out the first, and then call itself with the second number and the sum of the two that were input
Fibonacci (A, B)
Begin
write (A)
Fibonacci (B, A+B)
End
Ideally there is code somewhere to stop it (like a threshold value), but there doesn’t need to be. If there isn’t, the code just runs until the user terminates the program.
My backups are recursive.
I use recursion with computers all the time — if I swear at them once and it has no effect, I recurse them repeatedly.
The joke must be Hopcroft’s. I have Aho & Ullman’s Compiler Design book and “recursion” doesn’t recurse there.
Good times … I recommended to a colleague the other day to use a recursive function to solve a problem. He stopped for a second and said “man … I always forget about that” … Sometimes though, it really is the most elegant solution and by FAR the easiest to read in the code.
I remember an advanced mathematics book (unfortunately I cannot remember the name, but I seem to recall it was one of the recommended textbooks on the first term Mathematical Physics, should be about Green functions or Hilbert spaces or something) that had, on the final index: Recursion (page X), where page X was, you guessed it, the page in question.
It seems to be a recurrent joke… (sorry!)
I remember it also had Index (pages X-2, X-1, X, I guess).