Mutual recursion: Difference between revisions
Content added Content deleted
No edit summary |
(added Ursala) |
||
Line 924: | Line 924: | ||
done |
done |
||
echo</lang> |
echo</lang> |
||
=={{header|Ursala}}== |
|||
Forward declarations are not an issue in Ursala, which allows any |
|||
definition to depend on any symbol declared in within the same |
|||
scope. However, cyclic dependences are not allowed unless the |
|||
programmer is prepared to explain what they mean. If the recurrence |
|||
can be solved using a fixed point combinator, the compiler can be |
|||
directed to use one by the #fix directive. A fixed point combinator |
|||
appropriate for first order functions is available as a library |
|||
function, as shown below. User defined fixed point combinators |
|||
allowing recursive definitions of things other than functions are also |
|||
possible. Note that this feature is rarely needed for defining |
|||
functions because the language |
|||
provides other more convenient mechanisms. |
|||
<lang Ursala> |
|||
#import std |
|||
#import nat |
|||
#import sol |
|||
#fix extensional_function_fixer |
|||
F = ~&?\1! difference^/~& M+ F+ predecessor |
|||
M = ~&?\0! difference^/~& F+ M+ predecessor</lang> |
|||
This test program applies both functions to the first |
|||
twenty natural numbers. |
|||
<lang Ursala>#cast %nLW |
|||
test = ^(F*,M*) iota 20</lang> |
|||
output: |
|||
<pre> |
|||
( |
|||
<1,1,2,2,3,3,4,5,5,6,6,7,8,8,9,9,10,11,11,12>, |
|||
<0,0,1,2,2,3,4,4,5,6,6,7,7,8,9,9,10,11,11,12>)</pre> |
|||
=={{header|x86 assembly}}== |
=={{header|x86 assembly}}== |