diff options
-rw-r--r-- | sicp.org | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -107,3 +107,43 @@ For a number as large as 1000000000, guile's =sqrt= function and =sqrt-sicp-alt= returns 31622.776601683792, =sqrt-sicp= returns 31622.776601684047; =sqrt-sicp= being slightly more precise than the other functions. +*** 9 +**** recursive process + +#+BEGIN_SRC scheme +(define (+ a b) + (if (= a 0) + b + (inc (+ dec a) b))) +#+END_SRC + +#+BEGIN_SRC +(+ 4 5) ----+ +(inc (+ 3 5)) |----+ +(inc (inc (+ 2 5))) |------+ +(inc (inc (inc (+ 1 5)))) |------+ +(inc (inc (inc (inc (+ 0 5))))) | +(inc (inc (inc (inc 5)))) +-------+ +(inc (inc (inc 6))) +-----| +(inc (inc 7)) +-----| +(inc 8) +-----| +9 <-----| +#+END_SRC + +**** iterative process + +#+BEGIN_SRC scheme +(define (+ a b) + (if (= a 0) + b + (+ (dec a) (inc b)))) +#+END_SRC + +#+BEGIN_SRC +(+ 4 5 --+ +(+ 3 6) | +(+ 2 7) | +(+ 1 8) | +(+ 0 9) | +9 <------+ +#+END_SRC |