Anonymous recursion: Difference between revisions

Added FreeBASIC
(Added Io entry.)
(Added FreeBASIC)
Line 801:
end function purefib
end function fib</lang>
 
=={{header|FreeBASIC}}==
FreeBASIC does not support nested functions, lambda expressions, functions inside nested types or even (in the default dialect) gosub.
 
However, for compatibility with old QB code, gosub can be used if one specifies the 'fblite', 'qb' or 'deprecated dialects:
<lang freebasic>' FB 1.05.0 Win64
 
#Lang "fblite"
 
Option Gosub '' enables Gosub to be used
 
' Using gosub to simulate a nested function
Function fib(n As UInteger) As UInteger
Gosub nestedFib
Exit Function
 
nestedFib:
fib = IIf(n < 2, n, fib(n - 1) + fib(n - 2))
Return
End Function
 
' This function simulates (rather messily) gosub by using 2 gotos and would therefore work
' even in the default dialect
Function fib2(n As UInteger) As UInteger
Goto nestedFib
 
exitFib:
Exit Function
 
nestedFib:
fib2 = IIf(n < 2, n, fib(n - 1) + fib(n - 2))
Goto exitFib
End Function
 
For i As Integer = 1 To 12
Print fib(i); " ";
Next
 
Print
 
For j As Integer = 1 To 12
Print fib2(j); " ";
Next
 
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
1 1 2 3 5 8 13 21 34 55 89 144
1 1 2 3 5 8 13 21 34 55 89 144
</pre>
 
=={{header|Go}}==
9,476

edits