Talk:McCarthy 91 function
The C example really needs to be removed from this article. The whole point of McCarthy's 91 function is exposition for the doubled recursion; there is no point whatsoever in including an iterative implementation, all it could possibly do is confuse. Moe Aboulkheir 05:32, 5 February 2006 (UTC)
Why is this interesting? I accept that it is an example of a recursive function, but I don't see why is deserves an article. And why is it restricted to positive integers? --Henrygb 12:30, 10 Aug 2004 (UTC)
It's interesting because it is. Also, because this function is hilarious.
Here's a function that Henrygb might find interesting. It returns 91 for all input, not just positive integers:
D(x) = 91
What was McCarthy's original motivation for this function? A simple illustration of recursion? --Bubba73 14:18, 27 May 2005 (UTC)
I just had to refactor the awkward Java implementation of McCarthy's function. Java is not suited to functional programming at all. -- Matthias
It is true that java is not well suited for showing recursive functions, but it is good to have its implementation because far more people can read java than lisp. It is a good example of recursion.
As for the lisp implementation, I just couldn't resist adding a nice clean lisp implementation of the same function. :) --pi 17:37, 15 July 2005 (UTC)
An algorithm does seldom correspondend one-on-one with its implementation in a relatively low level language such as java. We should keep the iterative version in java to show that you sometimes have to obfuscate your ideas to make your computer run them. -- Matthias
Shouldn't the M(n-10) in the beginning sentence just say n-10?Blueyoshi321 02:58, 22 November 2005 (UTC)
- I think so, I've changed it back. Nick8325 12:40, 22 November 2005 (UTC)
Why does it say C++, isn't that Java?
int mccarthy(int n) {
for (int c = 1; c != 0; ) { if (n > 100) { n = n - 10; c--; } else { n = n + 11; c++; } } return n;
}
isn't that Java, not C++? 71.141.127.117 06:19, 17 December 2005 (UTC)
- It seems to be valid C++ as well. In fact, unless I'm mistaken it's C99 too (not C89 because c is declared inside the for loop's initialiser). But in Java, it would need to be wrapped in a class to be valid...it would probably be best to call it C, I think. Nick8325 20:19, 17 December 2005 (UTC)
Why have an iterative example when the function should be written recursively? Besides that, I believe the for loop doesn't belong at all. I don't (yet) know lisp, but here is my try at translating it to Visual Basic:
Public Function MC91(n As Integer) If n < 1 Then GoTo NegError If n <= 100 Then MC91 = MC91(MC91(n + 11)) Else MC91 = n - 10 End If Exit Function NegError: Debug.Print "Function only defined for positive values of n" End Function
P.S. This function is interesting because of the doubled recursion
WallPhone 25 January 2006 (UTC)
Deletion
I am going to propose a deletion for this article in the next days as still no one can explain why this function is important. --Abdull 15:10, 5 March 2006 (UTC)
- It's a quite famous example of a recursive function. It's also nested, which is quite unusual - I can only think of the Ackermann function which also does that. It's probably not important, but plenty of people find it interesting, and (for example) MathWorld has an article on it, so why not Wikipedia? Nick8325 16:10, 5 March 2006 (UTC)
- Hi Nick. Actually, MathWorld seems to be the only other useful (Google) source on the Internet on this topic, the others just being mostly mirrors of Wikipedia. It would be great to explain why McCarthy should have come up with this function or proof if McCarthy really did, otherwise it seems like a Nihilartikel or in-joke. --Abdull 19:03, 6 March 2006 (UTC)
- Searching for McCarthy 91 function -wikipedia seems to clear out a lot of the mirrors, and there are still a fair number of references left. I don't know why he came up with it, but it's definitely real - I'd heard of it before I read about it here. Looking around a bit more, it seems to have appeared in an article called "Properties of programs and partial function logic", published in 1970. It seems to be in a library near me, I might go and look for it... Nick8325 20:14, 6 March 2006 (UTC)