After we correct for the algorithmic differences, is there really that much difference between...
fibo 0 = 1 fibo 1 = 1 fibo x = fibo (x-1) + fibo (x-2)
...and...
function fibo (x)
{
switch (x) {
case 0: return 1;
case 1: return 1;
default: return fibo(x-1) + fibo(x-2);
}
}
...and...
sub fibo
{ my $x = shift;
$x == 0 ? 1 :
$x == 1 ? 1 :
fibo($x-1)+fibo($x-2)
}
...and...
template<class T> T fibo(T x)
{
switch (x) {
case 0: return 1;
case 1: return 1;
default: return fibo(x-1) + fibo(x-2);
}
}
...and...
(defun fibo (x)
(case x (0 1)
(1 1)
(t (+ (fibo (- x 1)) (fibo (- x 2))))))
...and...
def fibo(x)
case x
when 0: 1
when 1: 1
else fibo(x-1) + fibo(x-2)
end
end
fun fibo x = case x of
0 => 1
| 1 => 1
| n => fibo(n-1) + fibo(n-2)
(define (fibo x)
(case x ((0 1) 1)
(else (+ (fibo (- x 1)) (fibo (- x 2))))))
update: And the languages are: Haskell, Javascript, Perl, C++, Common Lisp, Ruby, SML, and Scheme.
Not really--they're all not P
Not really--they're all not Python. :-)
They actually look better now
After you applied the formatting most of those examples look better to me than the Haskell syntax. I like the use of indenting to indicate relationships, particularly that a block of code all belongs to a function. That seems to be a well established programming idiom in almost every language. Apparently most other people like it too.
The funny thing about the original example is that he uses long function names and long variable names to make the target languages look worse than they actually are.
Thanks for re-writing them. :)