Anonymous recursion: Difference between revisions

Delphi version of Anonymous Recursion
(edit a lambdatalk task)
(Delphi version of Anonymous Recursion)
Line 939:
 
Note that this method starts from 0, while the previous starts from 1.
 
=={{header|Delphi}}==
<lang Delphi>
program AnonymousRecursion;
 
{$APPTYPE CONSOLE}
 
uses
SysUtils;
 
function Fib(X: Integer): integer;
 
function DoFib(N: Integer): Integer;
begin
if N < 2 then Result:=N
else Result:=DoFib(N-1) + DoFib(N-2);
end;
 
begin
if X < 0 then raise Exception.Create('Argument < 0')
else Result:=DoFib(X);
end;
 
 
var I: integer;
 
begin
for I:=-1 to 15 do
begin
try
WriteLn(I:3,' - ',Fib(I):3);
except WriteLn(I,' - Error'); end;
end;
WriteLn('Hit Any Key');
ReadLn;
end.
</lang>
 
{{out}}
<pre>
-1 - -1 - Error
0 - 0
1 - 1
2 - 1
3 - 2
4 - 3
5 - 5
6 - 8
7 - 13
8 - 21
9 - 34
10 - 55
11 - 89
12 - 144
13 - 233
14 - 377
15 - 610
Hit Any Key
</pre>
 
=={{header|EchoLisp}}==
Anonymous user