Anonymous recursion: Difference between revisions
Content added Content deleted
(Added Quackery.) |
m (→{{header|Quackery}}: improved text) |
||
Line 2,336: | Line 2,336: | ||
would cause the nest <code>[ dup 1 - recurse ]</code>to be evaluated, and the program would go into a tailspin, recursively evaluating that nest until the return stack overflowed. |
would cause the nest <code>[ dup 1 - recurse ]</code>to be evaluated, and the program would go into a tailspin, recursively evaluating that nest until the return stack overflowed. |
||
This limitation can be overcome with the understanding that recursion can be factored out into two ideas, i.e. self |
This limitation can be overcome with the understanding that recursion can be factored out into two ideas, i.e. self-reference and evaluation. The self-reference word in Quackery is <code>this</code>, which puts a pointer to the current nest on the data stack (usually just called "the stack") and the evaluation word is <code>do</code>, which takes an item from the stack and evaluates it. So <code>this do</code> is equivalent to <code>recurse</code>. |
||
The final example fixes the previous example by |
The final example fixes the previous example by using <code>this</code> and <code>do</code> to put the pointer to the current nest on the stack at the correct level of nesting and evaluate it within the nested nests. |
||
<pre>[ dup 0 < iff |
<pre>[ dup 0 < iff |