How to resolve the algorithm Anonymous recursion step by step in the Déjà Vu programming language
How to resolve the algorithm Anonymous recursion step by step in the Déjà Vu programming language
Table of Contents
Problem Statement
While implementing a recursive function, it often happens that we must resort to a separate helper function to handle the actual recursion. This is usually the case when directly calling the current function would waste too many resources (stack space, execution time), causing unwanted side-effects, and/or the function doesn't have the right arguments and/or return values. So we end up inventing some silly name like foo2 or foo_helper. I have always found it painful to come up with a proper name, and see some disadvantages: Some languages allow you to embed recursion directly in-place. This might work via a label, a local gosub instruction, or some special keyword. Anonymous recursion can also be accomplished using the Y combinator.
If possible, demonstrate this by writing the recursive version of the fibonacci function (see Fibonacci sequence) which checks for a negative argument before doing the actual recursion.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Anonymous recursion step by step in the Déjà Vu programming language
Source code in the déjà programming language
Y f:
labda y:
labda:
f y @y
call dup
labda fib n:
if <= n 1:
1
else:
fib - n 1
fib - n 2
+
Y
set :fibo
for j range 0 10:
!print fibo j
fibo-2 n:
n 0 1
labda times back-2 back-1:
if = times 0:
back-2
elseif = times 1:
back-1
elseif = times 2:
+ back-1 back-2
else:
recurse -- times back-1 + back-1 back-2
call
for j range 0 10:
!print fibo-2 j
You may also check:How to resolve the algorithm User input/Text step by step in the Falcon programming language
You may also check:How to resolve the algorithm Pierpont primes step by step in the Ring programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the C programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Bracmat programming language