Anonymous recursion: Difference between revisions

no edit summary
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
No edit summary
Line 1,169:
 
The recursive conditional operator <code>^?</code> differs from the ordinary conditional <code>?</code> seen at the outermost level by arranging for its predicate and component functions to be given an input of the form <math>(f,a)</math> where <math>a</math> is the original argument, and <math>f</math> is a copy of the whole function. Code within the function body may then access itself anonymously according to all the usual language idioms pertaining to deconstruction of tuples, and call itself by any of several recursion combinators, such as the pairwise recursion form <code>W</code> seen above.
 
=={{header|XPL0}}==
In XPL0 you can nest functions/procedures inside other
functions/procedures up to eight levels deep. This makes those nested
functions invisible to the outside, thus preventing namespace pollution.
 
<lang XPL0>include c:\cxpl\codes;
 
func Fib(X);
int X;
func ActualFib(N);
int N;
[if N<2 then return N
else return ActualFib(N-1) + ActualFib(N-2);
]; \ActualFib;
 
[if X<0 then [Text(0, "Error "); return 0]
else return ActualFib(X);
]; \Fib;
 
[IntOut(0, Fib(8)); CrLf(0);
IntOut(0, Fib(-2)); CrLf(0);
]</lang>
 
Output:
<pre>
21
Error 0
</pre>
 
{{omit from|PureBasic}}
772

edits