diff options
Diffstat (limited to 'mindmap/recursion.org')
-rw-r--r-- | mindmap/recursion.org | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/mindmap/recursion.org b/mindmap/recursion.org index bfedaca..3cc2a12 100644 --- a/mindmap/recursion.org +++ b/mindmap/recursion.org @@ -102,32 +102,12 @@ results block of this one, and you can see an exact mirroring of the first block So, the "going down" procedure is the same thing as pushing values onto some sort of stack, and the "going back up" procedure is exactly the same as popping those values off a stack! -** Computer Hardware Describes Recursion -Even though we can analogize pushing and popping off the stack to this recursion, there still isn't a clear definite -link to the two ideas in hardware. Therefore, I will do a demonstration using assembly. - -To start with, we will be comparing an assembly function that takes the factorial to this one in C: -#+begin_src C :results output :exports both -#include <stdio.h> - -int factorial(int x) { - if (x < 0) return -1; - else if (x == 0) return 1; - return x * factorial(x - 1); -} -int main(int argc, char **argv) { - printf("factorial of five: %d\n", factorial(5)); - return 0; -} +** Stacks Describe Recursion +To see more transparently how stacks relate to recursion, we use my programming language stem, which is a +concatenative programming language, as a more transparent example. +#+begin_src stem +factorial [ dup 0 <= [ 1 + ] [ dup 1 - factorial * ] ] def #+end_src - -#+RESULTS: -: factorial of five: 120 - -Because C is a compiled language, it is easier to see what is actually happening human-wise. However, -we will need to write and analyze some assembly in order to figure out what is actually going on. - -Assembly language section coming soon! We will be using NASM due to its readability. * TODO Recursion Describes…? * TODO Recursion is not Recursive |