Mutual recursion: Difference between revisions

Content added Content deleted
Line 936: Line 936:
Forward declarations are not an issue in Ursala, which allows any
Forward declarations are not an issue in Ursala, which allows any
definition to depend on any symbol declared in within the same
definition to depend on any symbol declared in within the same
scope. However, cyclic dependences are not allowed unless the
scope. However, cyclic dependences are not understood unless the
programmer is prepared to explain what they mean. If the recurrence
programmer explicitly accounts for their semantics. If the recurrence
can be solved using a fixed point combinator, the compiler can be
can be solved using a fixed point combinator, the compiler can be
directed to use one by the #fix directive. A fixed point combinator
directed to use one by the #fix directive as shown, in this case
with one of a family of functional fixed point combinators from
appropriate for first order functions is available as a library
a library. (There are easier ways to define these functions in Ursala
function, as shown below. User defined fixed point combinators
than by mutual recursion, but fixed points have other applications.)
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>
<lang Ursala>
Line 952: Line 949:
#import sol
#import sol


#fix general_function_fixer 0
#fix extensional_function_fixer


F = ~&?\1! difference^/~& M+ F+ predecessor
F = ~&?\1! difference^/~& M+ F+ predecessor
Line 966: Line 963:
<1,1,2,2,3,3,4,5,5,6,6,7,8,8,9,9,10,11,11,12>,
<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>
<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}}==